Hi Friend,

Today we can see about how alphabets can be displayed in ZigZag pattern using array method in Java.

Here i made it in 5 row. It can be done simple decision making concept.

The first understanding of this pattern program is the characters can be printed in row by row manner.

So firt row of character should be printed in such a way as below.

A                    I                    Q                         Y

Then the second row will be looking as below.

B         H        J         P       R            X                z

continue.

ABCDE – this happens because of i==j

EFGHI – This happens because of  i+j==8

 

Let us discuss the same through program:

Alphabet in ZigZag Pattern with Answer:

public class ZigZagAlphabet{

public static void main(String[] args) {

char ch[]={‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’};
for(int i=0;i<5;i++)
{
for(int j=0;j<ch.length;j++)
{
if(i==j || i+j==8 || j-i==8 || i+j==16 || j-i==16 || i+j==24 || j-i==24)
System.out.print(ch[j]);
else
System.out.print(” “);
}
System.out.println();
}

}

}

 

Output:

A                  I                    Q                    Y
B           H   J               P   R              X   Z
C      G         K         O       S         W
D  F              L    N           T    V
E                   M                 U