java - If else statement fails -
for (h = 1; h <= userinput; h++) { while (h <= userinput) { system.out.println("\npick y coordinate: (1 - " + row + ")"); try { userinput2 = stdin.nextint(); if (userinput2 > 0 && userinput2 <= row) { } else { system.out.println("make sure choose a" + " coordinate between 1 , " + row); } } catch (exception f) { system.out.println("make sure choosing coordinate" + " between 1 , " + row); stdin.next(); continue; } system.out.println("\npick x coordinate: (1 - " + column + ")"); try { userinput3 = stdin.nextint(); if (userinput3 > 0 && userinput3 <= column) { } else { system.out.println("make sure choose a" + " coordinate between 1 , " + column); } } catch (exception g) { system.out.println("make sure choosing coordinate" + " between 1 , " + column); stdin.next(); continue; } if (userguesses[userinput2][userinput3] == false) { userguesses[userinput2][userinput3] = true; } if (h == userinput) { break; } else { system.out.println("you've chosen coordinate coward!" + " try again!"); continue; } } }
for reason last if else
statement gets printed out (the sop apart of else). if it's first time selecting coordinates program. i'm new programming , maybe i've made rookie mistake that's glaringly obvious else.
remove nested while
loop. it's preventing h
changing,
for ( h = 1 ; h <= userinput; h++) { // while (h <= userinput) { // ... // } }
Comments
Post a Comment