 <p>The problems are caused by this:</p> <pre><code> { (char) c = (int) c - 32 + key + 127; System.out.println(c); } </code></pre> <p>The <code>(char) c = ...;</code> is completely invalid syntax. </p> <p>An assignment is supposed to look like this <code>c = ...;</code>. </p> <p>If you want / need to do a type cast before assigning, the type cast belongs on the right hand side of the assignment operator; i.e. <code>c = (char)(...)</code>.</p> <hr> <p>Anyway, what you have written has cause the Java parser (in your IDE) to get thoroughly confused ... and <em>spectacularly</em> misdiagnose the error as an attempt to declare a constructor, it the wrong context.</p> <p>Unfortunately, this happens sometimes ... though it is compiler dependent. The compiler was trying to be helpful, but the compiler / compiler writer "guessed wrong" about what you were trying to write at that point.</p> <p>Then it appears that the compiler's syntax recovery has inserted a <code>{</code> symbol into its symbol stream in an attempt to fix things. The second error complains that there is no <code>}</code> to match the phantom <code>{</code> that it inserted. Again, it has guessed wrong.</p> <p>But the root cause of this was your original syntax error.</p> <hr> <p>For the record, the <code>int</code> cast in your original expression is not necessary. You <em>could</em> (and IMO should) write the assignment as this:</p> <pre><code>c = (char) (c - 32 + key + 127); </code></pre> <p><strong>Explanation:</strong> in Java, the arithmetic operators always promote their operands to <code>int</code> (or <code>long</code>) before performing the operation, and the result is an <code>int</code> (or <code>long</code>). That means that your explicit cast of <code>c</code> to an <code>int</code> is going to happen anyway.</p>