260
Ladder Pattern in Java
In the previous sections, we have discussed many pattern programs. In this section, we will create Java program to print ladder with n steps.
Using for Loop
The following program prints the ladder with the gap between two side rails being 3 spaces.
LadderPatternExample1.java
Output:
Using Function
LadderPatternExample2.java
Output:
Let’s see another ladder pattern that prints ladder of numbers.
Ladder Number Pattern
Let’s see the approach to print ladder number pattern.
Approach:
- Read or initialize the number of steps and store it in a variable row.
- Define a for loop to print the row value and number for each row. Each iteration prints two side numbers.
- Define an if statement and check for condition (r< row). If the condition returns true, print stair row.
Let’s implement the above steps in a Java program.
LadderPatternExample3.java
Output:
Next TopicORM Tools in Java