0
    Scanner input = new Scanner(System.in);  //declaration of scanner
system.out.println("Please input the water system size in kiloliters of water");
double kiloliters = input.nextInt(); //getting the inputted value
if(input.hasNextInt()){//test if the inputted is an integer
 if(kiloliters > 1 && kiloliters < 65536){ // test if the inputted number is in between 1 and 65536
  if(kiloliters < 1000){ //test if the inputted number is less than 1000
   system.out.println("The health is 0.0");
  }
  if(kiloliters > 10000){//test if the inputted number is greater than 10000
   system.out.println("The health is 0.5");
  }
  if(kiloliters > 1000 && kiloliters < 10000){ //test if the inputted number is in between 1000 and 10000
   kiloliters = (kiloliters + 150)/140;
   system.out.println("The health is %.2f",kiloliters);
  }
 }
 else{
  system.out.println("Please input between 1 to 65536");
 }
}
else{
 system.out.println("Invalid Please input only an integer");

How would i go about verifying the input from the user to ensure it is between the numbers and if a user inputs a string of letters or a not a integer. And to also ask the user for the input again without exiting program? thanks.

Mat
  • 195,986
  • 40
  • 382
  • 396

0 Answers0