print

prime number program in java

``````import java.util.Scanner;
public static void main(String[] args) {
int n, count = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number :");
n = sc.nextInt();
for(int i=1; i<=n;i++){
if(n%i==0){
count++;
}
}
if(count==2){
System.out.println(n+" is a Prime number");
}else{
System.out.println(n+" is Not a Prime number");
}
}
}

``````

Output :

```
Enter a number :5
5 is a Prime number

Enter a number :6
6 is Not a Prime number
```

prime number code in java

``````import java.util.Scanner;
public static void main(String[] args) {
int i;
int j=2;
int ch = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter any number");
i = sc.nextInt();
if(i<=1)
ch =1;
while(j<= i/2){
if(i%j==0){
ch=1;
break;
}else{
j++;
}
}
if(ch==0){
System.out.println(i+ " is Prime number");
}
else{
System.out.println(i+" is not prime number");
}
}
}``````

Output :

```
Enter any number
4
4 is not prime number

Enter any number
17
17 is Prime number
```