Write a program to print series of prime numbers upto n in Java1 min read
Input:
Primeupto 19
Output:
The prime nos. upto 19 are 2 3 5 7 11 13 17 19
Vishal Sharma Answered question
Here is my solution to
Write a program to print series of prime numbers upto n in Java
Program:
class Primeupto { public static void main(String arg[]) { int n,c=0,j=2; n=Integer.parseInt(arg[0]); System.out.println(" The prime nos. upto "+n+" are "); for( j=2;j<=n;j++) { c=0; for(int k=2;k<=j/2;k++) { if(j%k==0) c++; } if(c==0) System.out.print("\t"+j); } } }
Output:
Vishal Sharma Answered question