Computer Science, asked by Anonymous, 13 hours ago

write a program in java to print pattern :. 12345
22345
33345
44445
55555​

Answers

Answered by sanjumanoj9567
1

import java.util.Scanner;

public class Pattern {

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter n: ");

       int n = scanner.nextInt();

       for (int i = 1; i <= n; i++) {

           for (int j = 1; j <= n; j++) {

               if (j <= i) {

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

               } else {

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

               }

           }

           System.out.println();

       }

   }

Output:

12345

22345

33345

44445

55555

Similar questions