Create a new Class with name Disp_primes:
Output:(Click on image to enlarge):
(Comment if you have any doubts)
>
import java.util.Scanner;
public class Disp_primes {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int num = sc.nextInt();
System.out.println("prime numbers below "+num+" are :");
int rem=0;
if(num==2){
System.out.print(num+" is even prime");
}
else{
for(int i=num;i>2;i--){
int count=2;
while(count<i){
rem = i%count;
if(rem==0)
break;
else
count++;
}
if(rem!=0)
System.out.print(i+",");
}
if(num>2){
System.out.print("2");
}
}
}
}
public class Disp_primes {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int num = sc.nextInt();
System.out.println("prime numbers below "+num+" are :");
int rem=0;
if(num==2){
System.out.print(num+" is even prime");
}
else{
for(int i=num;i>2;i--){
int count=2;
while(count<i){
rem = i%count;
if(rem==0)
break;
else
count++;
}
if(rem!=0)
System.out.print(i+",");
}
if(num>2){
System.out.print("2");
}
}
}
}
Output:(Click on image to enlarge):
(Comment if you have any doubts)
>