+ 1

What does this code working?

public class Program { public static void main(String[] args) { int[ ] primes = {200, 330, 150, 170}; for (int t: primes) ; String [] names = {"Ajaml have","sherin have","muneer have","muhsin have"}; for (String x: names) { System.out.println(x+t); } } }

15th Nov 2017, 6:48 AM
ajmal yousuf
ajmal yousuf - avatar
4 Answers
+ 7
It doesn't work because the variable t only exists in the for loop.
15th Nov 2017, 6:54 AM
qwerty
qwerty - avatar
+ 2
you can access the variable t in 2nd loop only if it is nested loop of first one.For that. .. remove the semicolon (;) after for(int t: primes) and surround the rest code with curly braces{}
15th Nov 2017, 7:13 AM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
0
thanks for all
15th Nov 2017, 4:02 PM
ajmal yousuf
ajmal yousuf - avatar