Created
March 22, 2018 05:58
-
-
Save GammaBurst101/bd0195a1ec4d8f53def1973ecb4c0ff4 to your computer and use it in GitHub Desktop.
This java code finds the primorial of a number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class PrimorialFinder | |
{ | |
public static void main (String args[]) | |
{ | |
Scanner scan = new Scanner (System.in); | |
System.out.println ("Enter the number"); | |
int num = scan.nextInt(); | |
long primorial = 1, factor = 1; | |
while ( num != 0) | |
{ | |
factor ++; | |
boolean isPrime = true; | |
for (int i = 2; i < factor; i++) | |
{ | |
if (factor % i==0) | |
{ | |
isPrime = false; | |
break; | |
} | |
} | |
if (isPrime == true) | |
{ | |
num--; | |
primorial *= factor; | |
} | |
} | |
System.out.println ("Primorial: "+primorial); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment