Thread: new to java
View Single Post
Old 07-13-2004, 04:45 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,503
sde is on a distinguished road
just move the stdin line inside the while loop. then at the top of each loop, it will stop and ask for a new number:
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:");

  //start while loop and determine if integer is positive
  while(num!=0)
  {
    num = Integer.parseInt(stdin.readLine());
  
    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
__________________
Mike
sde is offline   Reply With Quote