Thread: new to java
View Single Post
Old 07-13-2004, 03:54 PM   #1 (permalink)
george12
Registered User
 
george12's Avatar
 
Join Date: Jul 2004
Posts: 1
george12 is on a distinguished road
Question new to java

Hey, really new to java and i have no idea how to stop the while loop. my output just continuely spits the number and message to the screen.

Any help would be muchly appreciated,

ta


Code:
//imports for keyboard I/O
import java.io.*; 

class PrimeCheck
{
public static void main(String[]args)throws java.io.IOException{
    //create a keyboard input stream

BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

//Variables for 
int num=-1;
boolean num1;
double num2;
String s1, s2; 

//Prompt user for integer

System.out.println("Enter a positive integer:");
num = Integer.parseInt(stdin.readLine());
{

//start while loop and determine if integer is positive
while(num!=0)
{
if(num>1)
{
    num1=((num % 2-1)==0); 
    if(num1==true)
    {
    
    System.out.println(num + " is a prime number.");
    } //end if

    else
    {
    System.out.println(num + " is not a prime number.");    
    } //end else
    
} //end if
else 
{

System.out.println("A positive integer was not entered, please enter a positive integer:");
}  //end else

}  //end while
}
}  //end main
}  //end class
george12 is offline   Reply With Quote