Java67: How to Print Pyramid Pattern in Java? Program Example
How to Print Pyramid Pattern in Java? Program Example * * * * * * * * * * * * * * * You need to write a Java program to print above pyramid pattern. How many levels the pyramid triangle would have will be decided by the user input. You can print this kind of pattern by using print() and println() method from System.out object. System.out.print() just prints the String or character you passed to it, without adding a new line, useful to print stars in the same line. While, System.out.println() print characters followed by a newline character, which is useful to move to next line. You can also use Scanner class to get input from the user and draw pyramid up to that level only. For example in above diagram, the pyramid has 5 levels. Analysis If you look at the problem then you will find that you need to print the star (*) character in the same line as well as a new line to generate a pyramidical pattern. You can also see that * are separated by space. In programming,Read full article from Java67: How to Print Pyramid Pattern in Java? Program Example
No comments:
Post a Comment