1. 程式人生 > >通過隨機數獲得學生成績,並把每個元素賦值為學生的分數成績,通過增強for循環遍歷結果。

通過隨機數獲得學生成績,並把每個元素賦值為學生的分數成績,通過增強for循環遍歷結果。

() nbsp sco math i++ oid 學生 length pac

package com.Summer_0419.cn;

/**
 * @author Summer
 * 通過隨機數獲得學生成績,並把每個元素賦值為學生的分數成績
 */
public class Test_Method12 {
    static int [] score = new int[25];//動態聲明一個25個空間的數組
    public static void main(String[] args) {
    random(score);//調用獲取隨機數的方法

    }

    private static void random(int [] its) {
        
for (int i = 0; i < its.length; i++) { System.out.println("請輸入第"+(i+1)+"個學生的成績"); its[i] = (int) ((Math.random()*100)+1);//隨機數獲取1到100的成績 } for (int i : its) { System.out.print(i+" ,");//增強for循環遍歷數組 } } }

通過隨機數獲得學生成績,並把每個元素賦值為學生的分數成績,通過增強for循環遍歷結果。