fork download
  1. import java.util.Random;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. final int M = 2; // 最小値
  8. final int N = 12; // 最大値
  9. Random rand = new Random();
  10. int x;
  11. int min = M;
  12. int max = N;
  13. boolean minFlag = false;
  14. boolean maxFlag = false;
  15.  
  16. for (int i = 0; i < 100; i++) {
  17. x = rand.nextInt(N - M + 1) + M;
  18. System.out.println(x);
  19. if (max < x) { // Nを超えるxがあったら
  20. max = x;
  21. maxFlag = true;
  22. }
  23. if (min > x) { // Mを下回るxがあったら
  24. min = x;
  25. minFlag = true;
  26. }
  27. }
  28.  
  29. if (maxFlag == true) {
  30. System.out.println(N+"を超える値があります。"+max+"です。");
  31. }
  32. if (minFlag == true) {
  33. System.out.println(M+"を下回る値があります。"+min+"です。");
  34. }
  35. System.out.println("この文以外に何も表示されなければ、正常です。");
  36.  
  37. }
  38.  
  39. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
3
11
5
6
10
7
4
11
4
6
8
2
7
3
5
7
6
7
6
3
12
9
2
11
12
6
10
7
6
2
7
5
11
8
10
12
7
12
4
9
4
7
2
6
10
10
5
4
12
8
3
6
3
12
11
5
7
12
4
11
2
9
12
6
7
12
9
10
5
4
2
3
9
3
12
10
9
10
12
11
3
3
3
3
8
2
6
5
9
12
10
4
6
10
10
3
12
8
6
6
この文以外に何も表示されなければ、正常です。