Follow on Facebook

Like and Share on Facebook

Wednesday, December 31, 2014

Write Pattern 12345 2345 345 45 5 in Java

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 = i; j <= n; j++) {

               System.out.println(j);

            }

            

        }

    }

Output:

12345
2345
345
45
5

No comments:

Post a Comment