0

私の言葉遣いが正しいかどうかはわかりません。これでより明確になることを願っています。

Integer[] Performed = new Integer[3];  

public String dived(){        
        while (this.numberAttempts<3){
            int n = this.numberAttempts;
            int k = Dive.chosenRandomly();
            this.Performed[n] = k ;
            numberAttempts += 1;
        }
        return null;
    }

k (乱数) の値をリストに保持して、どの数値が選択されたかがわかるようにします。while ループでリストに値を追加する方法はありますか?

[] の n を 3 未満の整数に置き換えると機能します。

4

1 に答える 1

0

ArrayList などのリストを使用して、ランダムな Integer を追加するだけです。

List<Integer> Performed = new ArrayList<Integer>();

public String dived(){        
    while (this.numberAttempts<3){
        int n = this.numberAttempts;
        int k = Dive.chosenRandomly();
        this.Performed.add(k) ;
        numberAttempts += 1;
    }
    return null;
}
于 2013-01-22T23:54:53.723 に答える