English

Write the program to display the following pattern: 1 2 3 4 52 2 3 4 53 3 3 4 54 4 4 4 55 5 5 5 5 - Computer Applications

Advertisements
Advertisements

Question

Write the program to display the following pattern:

1     2     3     4     5
2     2     3     4     5
3     3     3     4     5
4     4     4     4     5
5     5     5     5     5

Answer in Brief

Solution

public class Q9f
{ public static void main(String ar{])
{System.out.println("\n-------------------);
int a, b, c, p = 2;
for (a = 1; a <= 5; a++)
{
for (b = 1; b <= a; b++)
System.out.print(a + " "); // a...(row number) 2 is printed twice and so on

for (c = p; c <= 5; c++)
System.out.print(c + " ");

System.out.println();
p++;
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 1.1: Nested Loop - EXERCISES [Page 146]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.1 Nested Loop
EXERCISES | Q VI. 9. (f) | Page 146
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×