Q:

Java program to print pattern of alphabets

0

Example:

Input:
Enter number of rows: 5

Output:
A
BC
DEF
GHIJ

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now