Java program to print pattern of alphabets

In this java program, we are going to print pattern of alphabets? Here, we are taking input for number of rows and printing the pattern according to input.
Submitted by IncludeHelp, on November 07, 2017

Here, we are reading number of rows, and according to the input, pattern of alphabets will be printed.

Example:

Input:
Enter number of rows: 5

Output:
A
BC
DEF
GHIJ

Print pattern of alphabets in java

import java.util.Scanner;

public class Pattern11 
{
	public static void main(String[] args) 
	{
		//ASCII code of 'A'
		int alphabet=65;

		// create class.
		Scanner sc = new Scanner(System.in);

		// enter rows here.
		System.out.print("Enter number of rows: ");

		int rows = sc.nextInt();

		System.out.println("Here is your pattern....!!!");

		// will print numbers ladder in different way.
		for(int i=1;i<rows;i++)
		{            
			for(int j=1;j<=i;j++)
			{
				System.out.print((char)alphabet);
				alphabet++;
			}
			System.out.println();
		}
		sc.close();
	}
}

Output

First run:
Enter number of rows: 10
Here is your pattern....!!!
A
BC
DEF
GHIJ
KLMNO
PQRSTU
VWXYZ[\
]^_`abcd
efghijklm

Second run:
Enter number of rows: 5
Here is your pattern....!!!
A
BC
DEF
GHIJ

Java Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.