-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNo.java
More file actions
43 lines (43 loc) · 1.1 KB
/
PrimeNo.java
File metadata and controls
43 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Algo-:
1. Accept the value of n;
2. for loop i=2;i<=n/2;i++
a. if n%i=0 break;
3. if i=n/2+1 "prime no"
else
"not a prime no.
*/
package chapter01;
import java.util.Scanner;
/**
*
* @author harsh
*/
public class PrimeNo {
public static void main(String[] args){
int n, i;
System.out.println("Enter a no. : ");
n = Integer.parseInt(new Scanner(System.in).nextLine());
for ( i=2; i<=n/2; i++)
if(n%i==0) break;
if(i==n/2+1)
System.out.println("It's a prime no.");
else
System.out.println("Not a prime no.");
}
}
/*public class PrimeNo { //to print the prime nos.
public static void main(String[] args){
int n=1, i ,count=0;
while(n<100000){ \\fluctuate the integer
for ( i=2; i<=n/2; i++)
if(n%i==0) break;
if(i==n/2+1){
System.out.println(n+" is a prime no.");
count++;
}
n++;
}
System.out.println("Total nos. of primes : "+count);
}
}*/