Write a program in java to print prime number series using only 2 loops.
Please answer it if you can.
no spams
Answers
Answered by
0
Answer:
import java.util.*;
class prime{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter no. of terms");
int n=in.nextInt();
int c=0;
System.out.println(" The Prime numbers are:-");
for(int i=1;i<=n;i++)
{
for(int j=2;j<i;j++)
{
if(i%j==0)
c=1;
}
if(c==0)
{
System.out.print(i+", ");
}
c=0;
}
}
}
Explanation:
Enter no. of terms
20
The Prime numbers are:-
1, 2, 3, 5, 7, 11, 13, 17, 19,
Similar questions