java - Catch statement error code -


i trying set program prompts user enter values y or n string called resetvalue try pass value char r. know there errors code curious error code should catch statement should be. if user enters invalid value other y or n. looking through list of errors on oracle website there many don't know 1 best fit problem.

// prompts user reset program beginning if wish while(true){  system.out.print("\nwould enter new numbers? type (y) or (n): "); resetvalue = input.readline();     try {       char r = resetvalue.charat(0);       if( r == y || r == y ){          break;       }       else if( r == n || r == n){           reset = true;           break;       }    }    catch (error status here) {         system.out.print("please type either (y) or (n) on keyboard.");    } } 

depending on nature of readline, code should not throw exceptions save run time exception, nullpointerexception. it's not desirable catch those indicate missed assumption state of code (e.g. input stream has closed somehow).

omit try/catch block.

next, if user enters invalid option, give them chance correct it. need put else condition (aside fixing character literals) , continue loop until can break on valid input.

snippet:

} else {     system.out.println("invalid input - please enter y or n"); } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -