java.util.scanner - Need to subtract one from user input. How? Java -


basically need know how subtract 1 user input. trying x , y coordinate user place 2d array can 20x20, if user puts in 20, need program read 19 not out of bounds.

 x = keyboard.nextint() 

is have now.

// solution 1 x = math.min(19, math.max(0, keyboard.nextint() - 1));  // solution 2 x = keybord.nextint() - 1; if(x < 0) {   // error?!   x = 0; } else if(x > 19) {   // error?!   x = 19 } 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -