Computer Science, asked by deepakdey684, 1 month ago

1
2 3
4 5 6
7 8 9 10
using java​

Answers

Answered by anindyaadhikari13
2

\texttt{\textsf{\large{\underline{Solution}:}}}

The given problem is solved using language - Java.

public class Brainly{

   public static void main(String s[]){

       for(int a=1,i=1;i<=4;i++){

           for(int j=1;j<=i;j++)

               System.out.print(a++ +" ");

           System.out.println();

       }

   }

}

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • Line 1: Class declaration.
  • Line 2: Start of main().
  • Line 3: The outer loop starts. This loop iterates 4 times as there are four rows for the pattern. A variable named 'a' stores the number to be displayed in the pattern.
  • Line 4: The inner loop starts. It iterates 'i' times, i = {1, 2, 3, 4}.
  • Line 5: Value of 'a' is printed and it is incremented.
  • Line 6: A new line is inserted as we have to move to the next row after finishing each column.
  • Line 7: End of outer loop.
  • Line 8: End of main().
  • Line 9: End of class.

See attachment for output.

Attachments:
Similar questions