title: Converting a char to an int for int arithmetic in java
body: <p>i have a bit of strange confusion happening when trying to convert my char variables from my char array into ints.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class Luhn {
  
  private String cardNumber;
  private char[] cardArray;
  
  public Luhn(String cardNumber) {
      this.cardNumber = cardNumber;
      cardArray = new char[cardNumber.length()];
  
      for (int i = 0; i &lt; cardNumber.length(); i++) {
          cardArray[i] = cardNumber.charAt(i);
      }
  
  
  public void calculation() {
      for(int i = cardArray.length-1; i &gt;= 0; i-=2) {
          char y = cardArray[i];
          int x = (int) (cardArray[i] * 1);
          if(x &gt; 9) {
              //int total = 0;        
          }
      }
  
  
  }
  </code></pre>
  
  <p>I keep getting strange outputs in x. Something like 58. I'm accessing the array backwards and retrieving every 2nd number back to the front of the array. I basically want x to be whatever the number is in each array element. I know with this small piece of code it will overwrite x continuously, but i want it to be the number designated in the char array, not some random number not matching my array elements. The problem is in the calculation method where i try and convert the char to int. </p>
  
  <p>Please help</p>
  
  <p>Thanks.</p>
  
  <p>For Example;</p>