import java.util.Random; // Randomクラスを呼び出し public class Ex4_2 { public static void main(String[] args) { int x; boolean flg; float w; double y; Random rnd = new Random(); // Random クラスの宣言・使用準備 x = rnd.nextInt(6) + 1; // 0,1,2,3,4,5 の6個の数を一様乱数として作り,1足して代入 System.out.println(" サイコロ振るよ。えいっ! ... " + x + " だね!"); System.out.println(" 10面体賽子10回振るよ。えいっ!"); x = rnd.nextInt(10)+1; System.out.println(x); // 1回目 x = rnd.nextInt(10)+1; System.out.println(x); // 2回目 x = rnd.nextInt(10)+1; System.out.println(x); // 3回目 x = rnd.nextInt(10)+1; System.out.println(x); // 4回目 x = rnd.nextInt(10)+1; System.out.println(x); // 5回目 x = rnd.nextInt(10)+1; System.out.println(x); // 6回目 x = rnd.nextInt(10)+1; System.out.println(x); // 7回目 x = rnd.nextInt(10)+1; System.out.println(x); // 8回目 x = rnd.nextInt(10)+1; System.out.println(x); // 9回目 x = rnd.nextInt(10)+1; System.out.println(x); // 10回目 flg = rnd.nextBoolean(); // boolean型の乱数(true or false) System.out.println(" 論理値型サイコロ振るよ。えいっ! ... " + flg + " だね!"); w = rnd.nextFloat(); // float型の乱数(0.0〜1.0) System.out.println(" 単精度浮動小数点型サイコロ振るよ。... " + w + " だね!"); y = rnd.nextDouble(); // double型の乱数(0.0〜1.0) System.out.println(" 倍精度浮動小数点型サイコロ振るよ。... " + y + " だね!"); } }