Created
December 9, 2016 13:03
-
-
Save mokomokohitsuzi/fc5781da2099555913d622532a243c2b to your computer and use it in GitHub Desktop.
新・明解Java入門 演習6-9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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