+ 1

Can someone please explain this code for me? What does "t" represent in the program?

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

5th Oct 2020, 10:53 AM
KABIR ⚡🇳🇬
KABIR ⚡🇳🇬 - avatar
3 Respostas
+ 4
Steve Sajeev I thought "t" is a variable of type integer !?
5th Oct 2020, 11:09 AM
Abhay
Abhay - avatar
+ 2
T represents type. <T> specifically stands for generic type. According to Java Docs - A generic type is a generic class or interface that is parameterized over types.
5th Oct 2020, 10:54 AM
Steve Sajeev
Steve Sajeev - avatar
0
't' there is an Integer variable defined in for loop as local scope, and in every iteration it is assigned a value from the array primes... Like t=2,next t=3, next t=4,next t=5. So it is a user defined variable name..
5th Oct 2020, 2:16 PM
Jayakrishna 🇮🇳