LoginSignup
0
0

More than 5 years have passed since last update.

JAVAランダムな配列-出力される要素は重複を許可する

Posted at

(取り出し方はランダム、出力数は配列の要素数とイコール、出力される要素は重複を許可する)


import java.util.Random;

public class test1 {
    private static Random rand = new Random(System.currentTimeMillis());

    public static void main(String[] args) {
        test5();
    }

    public static void test5() {
        for (int i = 0; i < 10; i++) {
            System.out.println(rand.nextBoolean() ? "A" : "B");
        }
    }
}

▪️実行結果
Marimo-no-MacBook-Air:JAVA marimo$ java test1
A
B
B
A
B
A
A
A
A
A
Marimo-no-MacBook-Air:JAVA marimo$ java test1
A
A
B
B
A
A
A
A
B
B
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0