/* Java Program That Promotes The User For An Integer And Then Prints Out
All Prime Numbers upto That integer */
// File Name: prime.java
import java.io.*;
class prime {
public static void main(String[] args) throws IOException {
String s;
int n,i,j;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter The Number:");
s=in.readLine();
n=Integer.parseInt(s);
System.out.println("Given Value Of n Is :"+n);
System.out.print("Prime numbers Generated For "+n+" Are :");
for(i=0;i<n;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
System.out.print(i+",");
}
System.out.print("\n");
System.out.println("www.shashanktechnologies.blogspot.com");
}
}
OUTPUT:
COMPILATION: G:\shashank>javac prime.java
INTERPRETATION: G:\shashank>java prime
No comments:
Post a Comment