I am trying to create a simple java program for a chess tournament, which will save game results in an array. Results will be stored according to users choice, they may be input from keyboard, or using results that are already in the array, OR generate random sequence of numbers 1.0, 0.0, 0.5. (win, loss, draw)
So far I know how to generate random numbers in a specific range, using java.util.Random;
public static void main(String[] args) {
double a[][] = {{0.5, 0.5, 0.5, 0.5, 0.5},
{0, 1, 0, 1, 1},
{0.5, 1, 0.5, 0.5, 0},
{0, 0.5, 0, 0.5, 0},
{1, 1, 1, 1, 1},
{0, 0, 0, 0.5, 0.5},
{0, 0.5, 0, 0, 1}};
int i, j;
int ch;
System.out.print("mode (1, 2 or 3): ");
Scanner sc = new Scanner(System.in);
ch = sc.nextInt();
Random rnd = new Random();
switch (ch) {
case 1 -> { for (i=0; i<a.length ;i++) {
for (j=0; j<a[i].length; j++) {
a[i][j] = sc.nextDouble();
}
}
}
case 2 -> { for (i=0; i<a.length; i++) {
for (j=0; j<a[i].length; j++) {
a[i][j] = rnd.nextDouble();
}
}
}
case 3 -> { for (i=0; i<a.length; i++) {
for (j=0; j<a[i].length; j++) {
a[i][j] = a[i][j];
}
}
}
default -> {
System.out.println("mode error");
sc.close();
return;
}
}
sc.close();
for (i=0; i<a.length; ++i) {
for (j=0; j<a[i].length; ++j) {
System.out.printf("%.1f" + " ", a[i][j]);
}
System.out.println();
}
so case 2 of switch statement is giving me issues, since it gives an output of random numbers in a range of 0 to 1, but game results must be stored in values of 1.0, 0.5, and 0.0