I wanted to print 4 numbers (that is divisible by 3 and 6) before x and store it in an array. For example if I input 29 the code will print 6 12 18 24.
int array[] = new int [4];
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int x = sc.nextInt();
for(int counter = 1; counter <= x; counter++) {
if (counter % 3 ==0 && counter % 6 ==0){
for ( int i=0; i<array.length; i++){
array[i]=counter;
System.out.println(array[i]);
}
}
}
my code so far which doesn't even work
Aucun commentaire:
Enregistrer un commentaire