Print Alphabet Pattern in Java
Using For and while loop you can easily Print Alphabet Pattern in Java, in place of print() function use System.out.print(); and for new line use println() function.Code for Print Alphabet Pattern in Java
class ABCDPattern
{
public static void main(String abc[])
{
int alphabet=65; //ASCII value of A
for(int i=1;i<5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print((char)alphabet);
alphabet++;
}
System.out.println();
}
}
}
Output
A
AB
ABC
ABCD
No comments :
Post a Comment