+ 5
Is it correct code becz I don't get the output
5 Réponses
+ 3
I try it and it doesn't compile Edoardo Rosso put thx, I appreciate your help
+ 1
Initially after array initialization, it's values are defaultly set to 0.
And by loop,
for(int i: num){ //I is assigned as i= 0,next 0,......0 all 10 array elements , so you always set to num[0] to input value. Only num[0] is gets changed but not any other values by this loop by next line. So it's incorrect to use this for each loop here.
num[i] = input.nextInt();
}
You have also printing and comparing array 'num' instead of using 'i'...
0
No, it does not compile.
0
You're cycling through num using an enhanced for loop with the intention of putting elements into it. What you're telling the compiler is "do this for every element in num array" when your num array size is 0. Use a regular for loop instead:
for (int i = 0; i < 10; i++ ) {
//enter the number in num[i]
}
0
Shahedmub You're comparing num instead of i two times in the if statement too