java - Loop user input until conditions met -
i need ask user input number used start of range, , input number end of range. start number has 0 or greater , end number cannot larger 1000. both numbers must divisible 10. have found way meet these conditions, if not met program tells user input incorrect. possible me code after user inputs check make sure conditions met, , if not loop , make them input again. here code have far.
scanner keyboard = new scanner(system.in); int startr; int endr; system.out.println("enter starting number of range: "); startr=keyboard.nextint(); if(startr%10==0&&startr>=0){ system.out.println("enter ending number of range: "); endr=keyboard.nextint(); if(endr%10==0&&endr<=1000){ }else{ system.out.println("numbers not divisible 10"); } }else{ system.out.println("numbers not divisible 10"); }
easy do-while:
scanner keyboard = new scanner(system.in); int startr, endr; boolean = false; { system.out.println("enter starting number of range: "); startr = keyboard.nextint(); if(startr % 10 == 0 && startr >= 0) = true; else system.out.println("numbers not divisible 10"); } while (!good); = false; { system.out.println("enter ending number of range: "); endr = keyboard.nextint(); if(endr % 10 == 0 && endr <= 1000) = true; else system.out.println("numbers not divisible 10"); } while (!good); // stuff
Comments
Post a Comment