PATTERN PRINTING JAVA
Java code for printing a right-angled pattern using asterisks
SOURCE CODE:
Explanation:
- This code defines a class called
RightAngledPattern
with a singlemain
method that will be executed when the program is run. - The first line of the
main
method creates a variable calledrows
and assigns it a value of 5. This variable will control the number of rows in the pattern. - The next line starts a
for
loop that will iterate over each row in the pattern. The loop runs as long asi
is less than or equal torows
. In each iteration of the loop,i
is incremented by 1. - Inside the outer loop, there's another
for
loop that will iterate over each asterisk in the current row. The loop runs as long asj
is less than or equal toi
. In each iteration of the loop,j
is incremented by 1. - Inside the inner loop, there's a call to
System.out.print()
which prints an asterisk followed by a space, without moving to the next line. - After the inner loop has finished printing all the asterisks for the current row, there's a call to
System.out.println()
which moves the cursor to the next line.
When you run the code, the output will be:
Thanks for readingsend the feedbacks after reading.
Please support!
Please support!
Comments
Post a Comment