Advertisements
Advertisements
Question
Write the program to display the following pattern:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Answer in Brief
Solution
public class Q9h
{ public static void main(String ar{])
System.out.println("\n--------------------");
int i, j, p = 1;
for (i = 1; i <= 5; i++)
{ System.out.println();
for(j = 1: j <= i; j++)
System.out.print(p++ + "\t");
}}
shaalaa.com
Is there an error in this question or solution?
Chapter 1.1: Nested Loop - EXERCISES [Page 147]