The idea is to show a ladder at a given height, but a number of conditions must be met.
import java.io.IOException; import java.util.Scanner; //TODO: add Exceptions public class Mario { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int nHeight, step, space, sharp, a = 1, b; boolean integer; do { System.out.print("Enter height of pyramid: "); nHeight = scanner.nextInt(); integer = scanner.hasNextInt(); } while ( (!integer) || (nHeight < 1) || (nHeight > 23)); b = nHeight - 2; for(step = 0; step < nHeight; step++) { for(space = 0; space < nHeight - a; space++) { System.out.print(" "); } for(sharp = 0; sharp < nHeight - b; sharp++) { System.out.print("#"); } a++; b--; System.out.println(); } } } One of the conditions is that something entered must be an integer number. I decided to check using the integer variable in the do while loop. However, the program does not work correctly, that is, the result is issued after several attempts to enter and it does not matter whether restrictions are passed or not.
But if the 17th line is removed (and the condition! Integer), then the program works as it should according to the other two conditions. What is wrong with this line? Why she does not give the desired result? How to fix this?
