title: Java character based queue using an array
body: <p>Below is a code for a character based queue using an array. Currently, I'm able to push characters into the array but I get some random numbers when returning once I check the index. What needs to be changed here in order to see a pushed character? For example "Array Deque : 97" returns 97 instead of the a.</p>
  
  <p>------------output---------------
    Array Deque Operations</p>
  
  <ol>
  <li>add</li>
  <li>get</li>
  <li>set</li>
  <li>remove</li>
  <li>check empty</li>
  <li>clear</li>
  <li><p>size</p>
  
  <p>1</p></li>
  </ol>
  
  <p>Enter index and element</p>
  
  <p>0</p>
  
  <p>a</p>
  
  <p>Array Deque : 97 </p>
  
  <p>Do you want to continue (Type y or n) </p>
  
  <hr>
  
  <pre><code>import java.util.Scanner;
  class ArrayDeque
  {
  private int[] a;
  private int j, n;
  public ArrayDeque()
  {
  j = 0;
  n = 0;
  resize();
  }
  
  public boolean isEmpty()
  {
  return n == 0;
  }
  
  public void clear()
  {
  j = 0;
  n = 0;
  resize();
  }
  public int getSize()
  {
  return n;
  }
  private void resize()
  {
  int[] temp = new int[Math.max(2 * n, 1)];
  for (int k = 0; k &lt; n; k++)
  temp[k] = a[(j + k) % a.length];
  a = temp;
  j = 0;
  }
  public int get(int i)
  {
  return a[(j + i) % a.length];
  }
  
  public int set(int i, int x)
  {
  int y = a[(j + i) % a.length];
  a[(j + i) % a.length] = x;
  return y; 
  }
  
  void add(int i, int x)
  {
  if (n + 1 &gt; a.length)
  resize();
  if (i &lt; n/2)
  {
  j = (j == 0) ? a.length - 1 : j - 1;
  
  for (int k = 0; k &lt;= i - 1; k++)
  a[(j + k) % a.length] = a[(j + k + 1)%a.length];
  }
  else
  {
  for (int k = n; k &gt; i; k--)
  a[(j + k) % a.length] = a[(j + k - 1)%a.length];
  }
  a[(j + i) % a.length] = x;
  n++;
  }
  
  public int remove(int i)
  {
  int x = a[(j + i) % a.length];
  if (i &lt; n/2)
  {
  
  for (int k = i; k &gt; 0; k--)
  a[(j + k) % a.length] = a[(j + k - 1) % a.length];
  
  j = (j + 1) % a.length;
  }
  else
  {
  for (int k = i; k &lt; n - 1; k++)
  a[(j + k) % a.length] = a[(j + k + 1) % a.length];
  }
  n--;
  if (3 * n &lt; a.length)
  resize();
  return x;
  }
  
  public void display()
  {
  System.out.print("\nArray Deque : ");
  int p = j;
  for (int i = 0; i &lt; n; i++)
  {
  System.out.print(a[p % a.length] +" ");
  p++;
  }
  System.out.println();
  }
  }
  
  public class ArrayDequeTest
  {
  public static void main(String[] args)
  {
  Scanner scan = new Scanner(System.in);
  System.out.println("Array Deque Test\n");
  
  ArrayDeque ad = new ArrayDeque();
  
  char ch;
  do
  {
  System.out.println("\nArray Deque Operations\n");
  System.out.println("1. add");
  System.out.println("2. get");
  System.out.println("3. set");
  System.out.println("4. remove");
  System.out.println("5. check empty");
  System.out.println("6. clear");
  System.out.println("7. size");
  
  int choice = scan.nextInt();
  switch (choice)
  {
  case 1 :
  System.out.println("Enter index and element");
  ad.add(scan.nextInt(), scan.next().charAt(0) );   
  break;
  case 2 :
  System.out.println("Enter index");
  System.out.println("Result : "+ ad.get(scan.nextInt() ));
  break;
  case 3 :
  System.out.println("Enter index and element");
  ad.set(scan.nextInt(), scan.nextInt() );
  break;
  case 4 :
  System.out.println("\nEnter index");
  ad.remove(scan.nextInt() );
  break;
  case 5 :
  System.out.println("\nEmpty Status : "+ ad.isEmpty());
  break;
  case 6 :
  System.out.println("\nArray Deque Cleared");
  ad.clear();
  break;
  case 7 :
  System.out.println("\nSize = "+ ad.getSize() );
  break;   
  default :
  System.out.println("Wrong Entry \n ");
  break;   
  }
  ad.display();   
  
  System.out.println("\nDo you want to continue (Type y or n) \n");
  ch = scan.next().charAt(0);
  } while (ch == 'Y'|| ch == 'y');
  }
  }
  </code></pre>