JAVA program to print the pattern :
11111
22222
33333
44444
55555
Expecting great approaches ! (from computer masters)
Answers
Answered by
6
Program :- {JAVA}
public class RectangularPattern
{
public static void main(String args [ ] )
{
for (int i = 1; i <= 5; i ++)
{
for (int j = 1; j <=5; j ++)
{
System.out.print(i + '' '');
}
System.out.print();
}
}
}
Output :-
11111
22222
33333
44444
55555
Answered by
5
Answer:
There are many approaches for this question
Approach 1:
class patt{
public static void main (String ar []){
for(int I=1;I<=5;I++){
for(int j=1;j<=I;j++)
System.out.print(I);
for(int j=5;j>I;j--)
System.out.print(I);
System.out.println();
}
Approach 2:
class patt{
public static void main (String ar []){
for(int I=1;I<=5;I++){
for(int j=1;j<=5;j++)
System.out.print(I);
System.out.print();
}
}
Approach 3:
class patt{
public static void main (String ar []){
for(int I=1;I<=5;I++)
System.out.println(Integer.toString(I).repeat(5));
}
}
Note:-
- Integer.toString() converts integer to string.
Similar questions