So I'm trying to create a program that creates a randomly generated array with numbers between 0 and 10. Every time a number inside the 4x4 array is odd I want it to generate a brand new array and print every array discarded aswell until it creates a 4x4 array with only even numbers. The problem right now is that I can't understand how to fix the last "for" and make it work properly with the boolean "b" that is supposed to restart the creation of the array.
import java.util.Scanner;
public class EvenArrayGenerator{
public static void main(String a[]){
Boolean b;
do{
b=true;
int[][] Array = new int[4][4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
Array[i][j] = (int)(Math.random()*11);
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
System.out.print(Array[i][j] + " ");
}
System.out.println();
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(Array[i][j] % 2!=0)
b=false;
}
}
}while(b);
}
}
Aucun commentaire:
Enregistrer un commentaire