Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Sunday, 19 November 2017

Alphabet Pattern Programs in Java

Java Alphabet Pattern Programs

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.


Share:

18 comments:

  1. Your all java pattern post very useful. thanks for sharing this.

    ReplyDelete
  2. how can we write:
    a b c d e
    b c d e
    c d e
    d e
    e

    ReplyDelete
  3. how can we print...
    (a)
    (a+b)
    (a+b+c)
    (a+b+c+d)
    (a+b+c+d+e)

    ReplyDelete
  4. How can we print ...
    A B C D E
    A B C D A
    A B C A B
    A B A B C
    A A B C D

    ReplyDelete
    Replies
    1. import java.util.*;
      public 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");
      }
      }
      }

      Delete
  5. Help me printing
    A
    B C
    D E F
    B C
    A

    ReplyDelete
  6. Nice tutorial for java learners

    ReplyDelete
  7. I 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.
    Java Training in Bangalore

    ReplyDelete
  8. Nice java alphabet pattern programs

    ReplyDelete
  9. How can we print
    L O V E
    O O V E
    V V E V
    E E E E

    ReplyDelete
  10. A B C D E
    B C D E
    C D E
    D E
    E

    ReplyDelete
  11. How can we we print
    A
    BC
    DEF
    GHIJ
    KLMNO
    from right side not left

    ReplyDelete
  12. How can we print
    ABCDE
    FGHIJ
    KLMNO
    PQRST
    UVWXY

    ReplyDelete
  13. How to print the series
    A
    Aa
    AaB
    AaBb
    AaBbC

    ReplyDelete
  14. how to print the series
    a
    a b a
    a b c b a
    a b a b

    ReplyDelete
  15. 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

    ReplyDelete
  16. Thank 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

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate