import java.util.Scanner;
public class PrimeChecker
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
// Create an array of prime numbers between 0 and 50
// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
int[] arrayPrime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
System.out.println ("**********************");
System.out.println ("* PRIME CHECKER 3000 *");
System.out.println ("**********************");
System.out.println ();
System.out.print ("Please enter a number between 1 and 50: ");
int number = scan.nextInt ();
boolean isPrime = false;
// check to see if the number entered is prime
for (int i = 0; i< arrayPrime.length; i++)
{
if (number == arrayPrime[i])
isPrime = true;
}
if (isPrime)
System.out.println ("Yes, " + number + " is a prime number.");
else
System.out.println ("No, " + number + " is not a prime number.");
}
}
public class PrimeChecker
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
// Create an array of prime numbers between 0 and 50
// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
int[] arrayPrime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
System.out.println ("**********************");
System.out.println ("* PRIME CHECKER 3000 *");
System.out.println ("**********************");
System.out.println ();
System.out.print ("Please enter a number between 1 and 50: ");
int number = scan.nextInt ();
boolean isPrime = false;
// check to see if the number entered is prime
for (int i = 0; i< arrayPrime.length; i++)
{
if (number == arrayPrime[i])
isPrime = true;
}
if (isPrime)
System.out.println ("Yes, " + number + " is a prime number.");
else
System.out.println ("No, " + number + " is not a prime number.");
}
}
(0) Comments
Post a Comment