title: How to perform ASCII subtraction in java
body: <p>I've got a <code>char[]</code> array named <code>temp</code> which only contains <code>a</code>,<code>b</code> or <code>c</code>. Now if the two adjacent characters in the array are distinct, ie <code>temp[j]</code> and <code>temp[j+1]</code> contains <code>a</code> and <code>b</code> respectively, I need to store <code>c</code> in <code>temp[j+1]</code> . </p>
  
  <p>And for that, I defined, </p>
  
  <pre><code>private static final int CHARSUM = 294;
  </code></pre>
  
  <p>which is the sum of ASCII value of <code>a</code>,<code>b</code> and <code>c</code>. and what I tried was to subtract the sum of <code>temp[j]</code> and <code>temp[j+1]</code> from <code>294</code>.</p>
  
  <pre><code>temp[j+1] = CHARSUM-(temp[j]+temp[j+1]);
  </code></pre>
  
  <p>which should store the value <code>c</code> if the other values were <code>a</code> and <code>b</code>.
  But here, <strong>the problem is:</strong></p>
  
  <blockquote>
    <p>incompatible types: possible lossy conversion from int to char</p>
  </blockquote>
  
  <p>And I tried changing to:</p>
  
  <ul>
  <li><code>private static final char CHARSUM = "294";</code></li>
  <li><code>temp[j+1] = (char)CHARSUM-(temp[j]+temp[j+1]);</code></li>
  <li><code>temp[j+1] = Character.getNumericValue(CHARSUM-(temp[j]+temp[j+1]));</code></li>
  </ul>
  
  <p>However, none of those did work and I did not find any other answers that would help me to solve the problem. So Any help to fix this will be highly appreciated. Thanks.</p>