+ 1
What means “:” in java?
Eg: for( int a:b) { System.out.println(a); }
4 Respuestas
+ 8
@Kuang Kyaw, please update your app to the latest version to get to that link.
The enhanced for loop (sometimes called a "for each" loop) is used to traverse elements in arrays.
The advantages are that it eliminates the possibility of bugs and makes the code easier to read.
Example:
int[ ] primes = {2, 3, 5, 7};
for (int t: primes) {
System.out.println(t);
}
/*
2
3
5
7
*/
The enhanced for loop declares a variable of a type compatible with the elements of the array being accessed. The variable will be available within the for block, and its value will be the same as the current array element.
So, on each iteration of the loop, the variable t will be equal to the corresponding element in the array.
+ 8
It's an enhanced for loop. You'll get it here:
https://www.sololearn.com/learn/Java/2209/
+ 1
I didn’t find! Please explain me
+ 1
Thanks you! 🤩🤩