Java Alphabet Pattern Programs
In the last article, We saw some most useful and different-different pattern programs in java like number pattern programs in java, star pattern programs in java but here we are going to discuss some basic and useful alphabet pattern programs in java with simple examples one by one.
Here we are creating alphabet pattern programs in java which is mostly asked for fresher and experienced in core java interviews.
Let 's start with alphabet pattern in java.
Alphabet Pattern 1 :
This example will show you characters from a to z in java.
class AtoZ
{
public static void main(String args[])
{
for(char ch = 'a'; ch <= 'z'; ch++)
{
System.out.println(ch);
}
}
}
Output: a
b
c
d
e
f
.
.
z
The above example will print characters from a to z.
Alphabet Pattern 2 :
A
AB
ABCe
ABCD
ABCDE
Solution :
class Demo1
{
public static void main(String args[])
{
for(int i = 1; i <6; i++)//for printing 5 rows
{
int alphabet = 65;//creating local variable with ASCII value of A i.e 65
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);//casted int value to char to get alphabet
alphabet++;
}
System.out.println();
}
}
}
Alphabet Pattern 3 :
A
BC
DEF
GHIJ
KLMNO
PQRSTU
Solution :
class Demo2
{
public static void main(String args[])
{
int alphabet = 65;//ASCII value of 'A'
for(int i = 1; i <7; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);
alphabet++;
}
System.out.println();
}
}
}
Alphabet Pattern 4 :
A
BB
CCC
DDDD
EEEEE
Solution :
class Demo4
{
public static void main(String args[])
{
int alphabet = 65;
for(int i = 1; i < 6; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);
}
System.out.println();
alphabet++;
}
}
}
Alphabet pattern programs can be created by using for loop, while loop.
Alphabet Pattern 5 :
A
BA
CBA
DCBA
Solution :
class Demo4
{
public static void main(String args[])
{
for(int i = 0; i <5; i++)
{
for(int j = 0, k = i; j <= i; j++, --k)
System.out.print((char)('A' + k));
System.out.print("\n");
}
}
}
Alphabet Pattern 6 :
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
Solution :
class Demo5
{
public static void main(String args[])
{
char c;
for(int i = 1; i <= 5; ++i)
{
c = 'A';
for(int j = i; j <5; ++j)
{
System.out.print(" ");
}
for(int k = 1; k <=i; ++k)
{
System.out.print(c);
++c;
}
c -= 2;
for(int l = 1; l <i; ++l)
{
System.out.print(c);
--c;
}
System.out.println();
}
}
}
Visit :
Java Array Programming Interview Questions.
Java String Programming Interview Questions.
Here we discussed Java alphabet pattern programs which is quite useful in java interviews. We will see some other most important alphabet pattern programs in coming articles.
Here we are creating alphabet pattern programs in java which is mostly asked for fresher and experienced in core java interviews.
Let 's start with alphabet pattern in java.
Alphabet Pattern 1 :
This example will show you characters from a to z in java.
class AtoZ
{
public static void main(String args[])
{
for(char ch = 'a'; ch <= 'z'; ch++)
{
System.out.println(ch);
}
}
}
Output: a
b
c
d
e
f
.
.
z
The above example will print characters from a to z.
Alphabet Pattern 2 :
A
AB
ABCe
ABCD
ABCDE
Solution :
class Demo1
{
public static void main(String args[])
{
for(int i = 1; i <6; i++)//for printing 5 rows
{
int alphabet = 65;//creating local variable with ASCII value of A i.e 65
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);//casted int value to char to get alphabet
alphabet++;
}
System.out.println();
}
}
}
Alphabet Pattern 3 :
A
BC
DEF
GHIJ
KLMNO
PQRSTU
Solution :
class Demo2
{
public static void main(String args[])
{
int alphabet = 65;//ASCII value of 'A'
for(int i = 1; i <7; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);
alphabet++;
}
System.out.println();
}
}
}
Alphabet Pattern 4 :
A
BB
CCC
DDDD
EEEEE
Solution :
class Demo4
{
public static void main(String args[])
{
int alphabet = 65;
for(int i = 1; i < 6; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print((char)alphabet);
}
System.out.println();
alphabet++;
}
}
}
Alphabet pattern programs can be created by using for loop, while loop.
Alphabet Pattern 5 :
A
BA
CBA
DCBA
Solution :
class Demo4
{
public static void main(String args[])
{
for(int i = 0; i <5; i++)
{
for(int j = 0, k = i; j <= i; j++, --k)
System.out.print((char)('A' + k));
System.out.print("\n");
}
}
}
Alphabet Pattern 6 :
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
Solution :
class Demo5
{
public static void main(String args[])
{
char c;
for(int i = 1; i <= 5; ++i)
{
c = 'A';
for(int j = i; j <5; ++j)
{
System.out.print(" ");
}
for(int k = 1; k <=i; ++k)
{
System.out.print(c);
++c;
}
c -= 2;
for(int l = 1; l <i; ++l)
{
System.out.print(c);
--c;
}
System.out.println();
}
}
}
Visit :
Java Array Programming Interview Questions.
Java String Programming Interview Questions.
Here we discussed Java alphabet pattern programs which is quite useful in java interviews. We will see some other most important alphabet pattern programs in coming articles.
Your all java pattern post very useful. thanks for sharing this.
ReplyDeletehow can we write:
ReplyDeletea b c d e
b c d e
c d e
d e
e
how can we print...
ReplyDelete(a)
(a+b)
(a+b+c)
(a+b+c+d)
(a+b+c+d+e)
How can we print ...
ReplyDeleteA B C D E
A B C D A
A B C A B
A B A B C
A A B C D
Pls ans
Deleteimport java.util.*;
Deletepublic class Pattern
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter No. of Lines :");
int l = in.nextInt();
int line = 0;
for(int i=l;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print((char)(64+j) + " ");
}
for(int k=1;k<=line;k++)
{
System.out.print((char)(64+k) + " ");
}
line++;
System.out.print("\n");
}
}
}
Help me printing
ReplyDeleteA
B C
D E F
B C
A
Nice tutorial for java learners
ReplyDeleteI was more than happy to uncover this great site. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
ReplyDeleteJava Training in Bangalore
Nice java alphabet pattern programs
ReplyDeleteHow can we print
ReplyDeleteL O V E
O O V E
V V E V
E E E E
A B C D E
ReplyDeleteB C D E
C D E
D E
E
How can we we print
ReplyDeleteA
BC
DEF
GHIJ
KLMNO
from right side not left
How can we print
ReplyDeleteABCDE
FGHIJ
KLMNO
PQRST
UVWXY
How to print the series
ReplyDeleteA
Aa
AaB
AaBb
AaBbC
how to print the series
ReplyDeletea
a b a
a b c b a
a b a b
Thank you very much. This is an easy way of explaining Java programme. This is will be very helpful for everyone. Java is becoming very popular in these days. These days Artificial Intelligence, Machine Learning, Chat GPT etc. came into existence very fast. Java is Full Stack Development, Full Stack Development: Guide to Building Modern Web Applications
ReplyDeleteThank you for the nice information. This is an easy way of explaining Java Programme. This will be very helpful for students. Java is becoming popular very fastly these days. The reason is Java is required in Artificial Intelligence, Machine Learning, Chat GPT ext. Java have a great place in IT field. Full stack in java is a nice option for career. Full Stack Development: Guide to Building Modern Web Applications .
ReplyDelete