Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created December 9, 2016 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/fc5781da2099555913d622532a243c2b to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/fc5781da2099555913d622532a243c2b to your computer and use it in GitHub Desktop.
新・明解Java入門 演習6-9
import java.util.Random;
import java.util.Scanner;
public class En06_09 {
public static void main(String[] args) {
Random rand = new Random();
Scanner stdIn = new Scanner(System.in);
// 要素数の処理
int element;
do {
System.out.print("要素数:");
element = stdIn.nextInt();
} while (element < 1);
System.out.println();
// 配列
int[] a = new int[element];
for (int i = 0; i < a.length; i++) {
// ランダム変数を作成し、代入
int randoms = rand.nextInt(10) + 1;
a[i] = randoms;
System.out.printf("a[%d] = %d\n", i, a[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment