Write A Program That Prints Prime Numbers Between 1 To N. Number N Should Be Accepted As Command Line Input?

1

1 Answers

Alongbar Daimary Profile
//Hi friend Here is Your Program. But Please Re compile it I've not compiled it Directly wrote Here.

Import java.io.DataInputStream;
class Prime{

public static void main(String[]ar){
int I=1,num=0;
DataInputStream this=new DataInutStream(System.in);

boolean Success=false;
System.out.println("Enter Any number:");

while(!Success){
 
try{
  num=Integer.valueOf(this.readLine());
  Success=true; 
  }
  catch(Exception E){
  System.out.println(E +"nReEnter Number");
}
}

calc NW=new calc();
int Pr=0;
for (I=1;I<=num;I++){
  Pr=NW.GetPrime(I);

  if (Pr>0)
  System.out.print("t" + Pr);
}

}

}
class calc{
  int GetPrime(int num){
int I=0;
for (I=2;I<num;I++){
  if (num%I==0){
  return 0;
  }

}
return num;   
  }
}

Answer Question

Anonymous