How to print the primes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to print the primes

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

14th Mar 2017, 11:05 AM
shivam saini
shivam saini - avatar
7 Answers
+ 1
Can you clarify to me of this program?
14th Mar 2017, 11:52 AM
shivam saini
shivam saini - avatar
+ 1
OK, Line 1:- You have declared an array named primes which can hold integer values and you have filled it with 2,3,5,7. Line 2:- This is called an enhanced-for loop, So,it will get every element of your array(that is primes) one by one, and put it in a new temporary variable​ named t.And then It will proceed to Print it. Hence this loop will print each number of your array ONE-BY-ONE, treating each element as t , temporarily. Hope that helps.If not ,msg me.
14th Mar 2017, 12:01 PM
Meharban Singh
Meharban Singh - avatar
+ 1
It means every number is stored to prime is temporary stored in t. And print one by one for (for loop).
14th Mar 2017, 12:07 PM
shivam saini
shivam saini - avatar
+ 1
Correct @Shivam , if u still didnt understand, I can explain in hindi/Punjabi
14th Mar 2017, 12:09 PM
Meharban Singh
Meharban Singh - avatar
+ 1
Ok.... I cleared properly.... Thanks
14th Mar 2017, 12:11 PM
shivam saini
shivam saini - avatar
+ 1
@Shivam, Anytime bro.
14th Mar 2017, 12:11 PM
Meharban Singh
Meharban Singh - avatar
0
?
14th Mar 2017, 11:49 AM
Meharban Singh
Meharban Singh - avatar