+ 2

Can someone explain me , Where 't' variable is initialized.?

public class Program { public static void main(String[] args) { int[ ] primes = {2, 3, 5, 7}; for (int t: primes) { System.out.println(t); } } } /* 2 3 5 7 */

24th Jan 2017, 2:43 AM
Devika
Devika - avatar
5 Respostas
+ 6
for(int t : primes) runs through every element in primes and assigns it to t.
24th Jan 2017, 3:01 AM
Robobrine
Robobrine - avatar
+ 1
whenever you see such kind of For loop declaration, you got to understand that every value of the array is executing in the loop through assignment to 't'.
30th Jan 2017, 4:45 AM
saurabh gupta
saurabh gupta - avatar
+ 1
:t will assign every elements of the array of each iteration, it shall transverse them
1st Feb 2017, 1:21 AM
Vicks D
Vicks D - avatar
- 1
in enhanced for loop t is initialized
28th Jan 2017, 9:43 AM
million informations
million informations - avatar
- 1
in enhanced for loop, the variable t is declared within the condition it self.. the value of t starts from 2 then 3 and so on in every iteration.. I,e in every iteration it gives out the values stored in the array primes stating from the very first one.. so in a way the value if t is initialized in the very first iteration when t becomes equal to 2
28th Jan 2017, 6:13 PM
Arnab Paul Choudhury
Arnab Paul Choudhury - avatar