1
2 3
4 5 6
7 8 9 10
using java
Answers
Answered by
2
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();
}
}
}
- 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
Social Sciences,
7 hours ago
Accountancy,
7 hours ago
English,
7 hours ago
Political Science,
14 hours ago
Math,
14 hours ago
Math,
8 months ago