How to limit user to only put in octal number in Java or loop until they do? -


so trying make user give me octal number or loop until do. cannot figure out. please help! thanks!

scanner keyboard = new scanner (system.in); boolean valid = false; while (!valid) //first loop unitl uers inputs correct value { // starts main loop     system.out.print("\n \ninput octal number: ");     string octatl = keyboard.next();     if((ocatal.contains("8") || ocatal.contains("9"))) // invalid input tester     {// starts second loop user input correct value         system.out.print("incorrect octal input...re-enter number.");         system.out.print("\ninput octal number: ");         string octatl = keyboard.next();     }// ends loop     valid = true; // end user input loop } 

you might simplify logic doing following (pseudo-code):

 boolean isvalid = false;  system.out.println("describe input should like")  string line;  while (!isvalid) {     line = keyboard.next();     if (line contains 012345678) { valid = true;}     else {system.out.println("reenter");}  }  work line 

by way want make sure numbers 0-7 entered .. don't want accept line octal not contain 8 or 9


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -