Follow on Facebook

Like and Share on Facebook

Wednesday, December 17, 2014

Java Program to Print pattern A BCD EDGHI JKLMNOP


Print pattern A BCD EDGHI JKLMNOP

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();
        char ch = 'A';
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= 2 * i - 1; j++) {
                System.out.println(ch);
                ch++;
            }
        }
    }
}


output 

Print pattern 

BCD 
EDGHI 
JKLMNOP

No comments:

Post a Comment