Java help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java help

What does regular colon ":" Means in java used in for loop for exmp class jags { public static void main(String[] args) { int bucky[]= {3,4,5,6,7}; int total=0; for(int x: bucky) { total+=x; } System.out.println(total); } } what the ":" does.

22nd Jul 2017, 5:25 PM
Rsps Ottoman
Rsps Ottoman - avatar
2 Answers
+ 2
This is a for each style loop. It will iterate through each element of the array bucky assigning its value to the variable x within the for each loop. : in this case acts as an "in" operator
22nd Jul 2017, 5:44 PM
ChaoticDawg
ChaoticDawg - avatar
0
how could you explain it in code how the : works, and whats alternative it?
25th Jul 2017, 3:13 PM
Rsps Ottoman
Rsps Ottoman - avatar