java - Input Validation on Parsed Code -


in below code user prompted enter numerical grade or hit "s" || "s" skip requirement. input in form of string. in case input not "s"||"s", input parsed double. code works perfectly. now, want input data validation , restrict input either "s" or "s" or number 0-100. there way without creating each term in form of string? e.g. ( line == "0" || line == "1" etc... till 100

// prompting user score (numerical grade) system.out.println("kindly input numerical score:    (enter s skip)");   // reading input line variable of string datatype string line = input.nextline();   // checking if line =="s" or =="s" skip, otherwise // value parsed double  if("s".equals(line) || "s".equals(line)) { }else try {         score = double.parsedouble(line);         system.out.println(score); } catch( numberformatexception nfe) {  } 

you parsing value double. check value of variable.

if (score >= 0 && score <= 100) {     doxyz();  } else {      notprocessing();  } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -