File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import java .util .*;
22public class CheckPrime {
33 public static void main (String [] args ) {
4- int x ,count =0 ;
5- System .out .println ("Enter the number" );
6- Scanner input =new Scanner (System .in );
7- x =input .nextInt ();
8- for (int i =1 ;i <=x ;i ++){
9- if (x %i ==0 ){
10- count ++;
11- }
12- }
13- if (count >2 || count ==1 ){
14- System .out .println (x +" is not a prime number" );
4+
5+ Scanner sc = new Scanner (System .in );
6+
7+ System .out .println ("enter a number" );
8+ int n = sc .nextInt ();
9+
10+ boolean isprime = true ;
11+ for (int i =2 ; i *i <=n ;i ++){
12+ if (n %i ==0 ){
13+ isprime = false ;
14+ break ;
15+ }
1516 }
16- else {
17- System .out .println (x +" is a prime number" );
17+ if (n <2 ){
18+ isprime = false ;
19+ }
20+ if (isprime ==false ){
21+ System .out .print (n +" is not a Prime Number" );
22+ }else {
23+ System .out .print (n +" is a Prime Number" );
1824 }
1925 }
2026}
27+
28+
29+
You can’t perform that action at this time.
0 commit comments