Write a program to print the triangular series:-
Note: Use nested for loop
Series: 1234
234
34
4
MalayaDhal:
Do you know the answer?
Answers
Answered by
8
Required Answer:-
Question:
Write a program to print the pattern.
1 2 3 4
2 3 4
3 4
4
Solution:
Here is the code.
- public class Pattern {
- public static void main(String[] args) {
- for(int i=1;i<=4;i++)
- {
- for(int j=i;j<=4;j++)
- System.out.print(j+" ");
- System.out.println();
- }
- }
- }
Explanation:
- Outer loop will run from i = 1 to n where 'i' is the control variable.
- Inner loop will run from j = i to n.
- Here, n is the number of rows. For example, if n = 4, inner loop will print 1 to 4 at first iteration of outer loop then it will print 2 to 4 at second iteration and so on.
Output is attached.
Attachments:
Similar questions