73
Zig Zag Star and Number Pattern in Java
In the previous section, we have discussed different pattern programs in Java. In this section, we will create Java programs for zig zag star and number patterns.
Steps to Print Zig Zag Number Pattern
- Print one backward slash first then one forward slash and continue.
- Enter the total characters in a row and store it an integer variable say row.
- Enter the total number of zig zag lines and store it in an integer variable say count.
- To print Backward slash:
- Take first for loop to print all the rows.
- Take an inner loop to print the column values.
- Then go on printing the numbers according to the iteration.
- To print forward slash:
- Take first for loop to print all the rows.
- Take inner loop to print the column values.
- Then go on printing the numbers according to the iteration.
Let’s implement the above steps in a Java program.
ZigZagNumberPattern.java
Output:
Zig Zag Star Pattern
ZigZagStarPattern.java
Output: