# Need assistance in writing a program to

on
I have attempted to write a program which takes an integer as an argument adn returns true if the argument is a prime number or false otherwise.  I have to demonstrate the method in a complete program.   Unfortunately, my program is not producing true or false based on whether the number is prime or not.  Not sure what direction to go, in order to obtain the correct output.  Any assistance will greatly be appreciated.
``````import java.io.*;

{
public static void main(String[] args) throws Exception
{

int TRUE = 1;
int FALSE = 0;

// Local variable declarations
int Number = 0;
int Prime = TRUE;

System.out.println("Enter number:");

if (Number < 1 && Number >= 50)
{
System.out.println("Error: Number is out of range\n");
}

// Check if Number is prime
if (Number == 1) Prime = FALSE;
if ((Number > 2) && (Number % 2 == 0)) Prime = FALSE;
if ((Number > 3) && (Number % 3 == 0)) Prime = FALSE;
if ((Number > 5) && (Number % 5 == 0)) Prime = FALSE;
if ((Number > 7) && (Number % 7 == 0)) Prime = FALSE;
if ((Number > 9) && (Number % 9 == 0)) Prime = FALSE;

// Print output
if (Prime == TRUE)
{
System.out.println("Number IS prime: True " + number);
}
else
{
System.out.println("Number is NOT prime: False " + number);
}
}
}
``````
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Java actually does have native booleans. You should probably use them instead of your virtual booleans using integers.

http://leepoint.net/notes-java/data/basic_types/26boolean.html

Your real problem is that you have TWO number variables "Number" and "number". Java is case sensitive so these are two unique variables. "Number" is always "0", which according to your program is prime. Here is your code fixed.
``````import java.io.*;

{
public static void main(String[] args) throws Exception
{
// Local variable declarations
int number = 0;
boolean prime = true;

System.out.println("Enter number:");

if (number < 1 && number >= 50)
{
System.out.println("Error: number is out of range\n");
}

// Check if number is prime
if (number == 1) prime = false;
if ((number > 2) && (number % 2 == 0)) prime = false;
if ((number > 3) && (number % 3 == 0)) prime = false;
if ((number > 5) && (number % 5 == 0)) prime = false;
if ((number > 7) && (number % 7 == 0)) prime = false;
if ((number > 9) && (number % 9 == 0)) prime = false;

// Print output
if (prime == true)
{
System.out.println("Number IS prime: True " + number);
}
else
{
System.out.println("Number is NOT prime: False " + number);
}
}
}
``````

Commented:
Thank you so very much for your prompt and accurate response.

Do more with