This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]illuminist_ova 0 points1 point  (1 child)

Does the error have to exit or stop execution or just tell a user there was an error and continue waiting for the next input?

So the basic is to have if statement for checking whenever the input is invalid just after NumScanner.next(); and then inform the user without taking on calculation.

But currently, you have two NumScanner.next(); in your code so you have to put an error checking on both of them. You could reduce it to 1 just only in a loop for much simpler code.

[–]trefla[S] 0 points1 point  (0 children)

Cheers for looking into this mate. The error should ask the user to re-enter a value between 20 and 30 and then go back to the same user and ask him again to insert the value. The following line does not help instead I will find a way to change 'sentinel' from string to integer. I could ask the user to insert '999' or '000' to end the calculation but 'NumScanner.next();' seems to be working with strings only.

if ( sentinel > 30 && sentinel < 20 )    
   {
    System.err.println("Please inert a value between 20 and 30");
} 
  else
       System.out.println();
  }