Make This pattern in java
1 2 3 4 5
2 2 3 4 5
3 3 3 4 5
4 4 4 4 5
5 5 5 5 5
Answers
Answered by
7
Question :-
- Print the following pattern in JAVA.
1 2 3 4 5
2 2 3 4 5
3 3 3 4 5
4 4 4 4 5
5 5 5 5 5
Understanding the Concept
This pattern can be divided into two parts:-
Part 1 :-
1
22
333
4444
55555
Part 2 :-
12345
2345
345
45
5
Here comes the solution ....
Co de:-
package Co der;
public class SquarePatt
{
public static void main (String ar [])
{
for (int I=1;I<=5;I++)
{
for(int j=1;j<=I;j++)
{
System.out.print(I+" "); //Part 1
}
for(int j=I;j<=5;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
Variable Description :-
- I:- loop variable
- j:- loop Variable
•Output Attached .
Attachments:
rimmi28:
Thanks
Similar questions