Write a java program to generate the following output:
112
123
1234
12345
123456
1234567
Answers
Answered by
4
Corrected Pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Your Answer:-
public class Ptt{
public static void main(String[] args) {
for(int i=1;i<=7;i++) {
for(int j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
Variable Description:-
- i :- loop variable
- j:- loop variable
Answered by
2
Answer:
Correct pattern:-
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Program:-
public class BrainlyAnswer
{
public static void main(String args[ ])
{
int i,j;
for(i=1;i<=7;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j + " ");
}
System.out.println();
}
}
}
- See the attachment for programs and output
- The logic is very simple first the outer loop runs if the condition is true 1<=7
- The body enters the inner loop for printing
- Now it prints j until i if i is 1 it prints 1 if i is 2 it prints 1 2 and so on so i<=limit so if you want a particular limit just change the condition with the limit.
Attachments:
Similar questions