Friday, January 23, 2015

Java Code for Alphabet Pattern 2


In the program the following star pattern will be printed.


A
AB
ABC
ABCD
ABCDE

The program is shown below :


import java.util.*;
class pattern6
{
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
int n;
System.out.println("Enter the number of rows");
n=scr.nextInt();

char c='A';
for(int i=1;i<=n;++i)
{
c='A';
for(int j=1;j<=i;++j)
{
System.out.print(c);
++c;
}
System.out.println();
}
}
}


OUTPUT
C:\Users\Ravi\Desktop\ravi>javac pattern6.java
C:\Users\Ravi\Desktop\ravi>java pattern6

Enter the number of rows
6

A
AB
ABC
ABCD
ABCDE
ABCDEF


No comments:

Post a Comment