Home » Java programs » Java basic programs

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





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.