Skip to content

Instantly share code, notes, and snippets.

@jimmykurian
Created February 3, 2012 22:11
Show Gist options
  • Save jimmykurian/1733174 to your computer and use it in GitHub Desktop.
Save jimmykurian/1733174 to your computer and use it in GitHub Desktop.
A Java program that prompts the user for an integer and then prints out all prime numbers up to that integer.
//PrimeNumbers.java - Jimmy Kurian
import java.util.Scanner;
class PrimeNumbers
{
public static void main(String[] args)
{
int n;
int p;
Scanner s=new Scanner(System.in);
System.out.println("Enter a number: ");
n=s.nextInt();
for(int i=2;i<n;i++)
{
p=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
p=1;
}
if(p==0)
System.out.println(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment