English, asked by MalayaDhal, 1 month ago

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 anindyaadhikari13
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.

  1. public class Pattern {
  2. public static void main(String[] args) {
  3. for(int i=1;i<=4;i++)
  4. {
  5. for(int j=i;j<=4;j++)
  6. System.out.print(j+" ");
  7. System.out.println();
  8. }
  9. }
  10. }

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