forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimorialNumber.java
More file actions
39 lines (36 loc) · 892 Bytes
/
PrimorialNumber.java
File metadata and controls
39 lines (36 loc) · 892 Bytes
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
/*
* Primorial number denoted by Pn# is the product of the first n prime numbers
*/
import java.util.*;
public class PrimorialNumber {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n : ");
int n = sc.nextInt();
int Pn=1;
for(int i=2;n>0;i++){
if(isPrime(i)){
Pn*=i;
if(n>1){
System.out.print(i+"*");
}
else{
System.out.print(i+"=");
}
n--;
}
}
System.out.print(Pn);
}
public static boolean isPrime(int x){
if(x<=1){
return false;
}
for(int i=2;i<=x/2;i++){
if(x%i==0){
return false;
}
}
return true;
}
}