Site hosted by Angelfire.com: Build your free website today!

Prime or Not

If you wish to view the code only, check this page. You can click the links and it should open up in a notepad file.

 

class FishSandwichB{
public static void main (String args[])
{
int number=19;
int HalfNumber;
int divisor;
boolean Prime=true;


System.out.println("This program will tell ja if the numba "+number+" is prime or not.");
HalfNumber=number/2;
//System.out.println(+HalfNumber);

for(divisor=2;divisor<=HalfNumber;divisor++)
{
if(number%divisor==0) Prime=false;
}
//report results
if(Prime==false) System.out.println("The number is not prime.");


else System.out.println("The number is prime.");
}
}

 

New Terms!

boolean: Holds two values: "true" and "false." Boolean values are not 1 or 0 as in C++. They must be set to "true" or "false", and they are not interchangable with integers.