Advertisements
Advertisements
प्रश्न
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
थोडक्यात उत्तर
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1.1: Nested Loop - EXERCISES [पृष्ठ १४६]