Skip to content

Instantly share code, notes, and snippets.

@GammaBurst101
Created March 22, 2018 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GammaBurst101/bd0195a1ec4d8f53def1973ecb4c0ff4 to your computer and use it in GitHub Desktop.
Save GammaBurst101/bd0195a1ec4d8f53def1973ecb4c0ff4 to your computer and use it in GitHub Desktop.
This java code finds the primorial of a number.
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