A Basic Calculator, illegal character

I’m working on the A Basic Calculator in the beginner Object-Oriented Java section.

Here’s my code:

// Calculator created by Naare.The.Good in 2022 (step19)

// (step1)
public class Calculator{
  // constructor (step2)
  public Calculator(){
    
  }
  // method (step3)
  // accepts two int parameters (step4)
  public int add(int a, int b){
    //return the sum of int a and int b (step5)
    return a + b;
  }

  public int subtract(int a, int b){
    //return the difference of int a and int b (step7)
    return a - b;    
  }

  public int multiply(int a, int b){
    //return the product of int a and int b (step9)
    return a * b;    
  }

  public int divide(int a, int b){
    //return the division of int a by int b (step11)
    return a / b;    
  }

  public int modulo(int a, int b){
    //return the int a modulo int b (step13)
    return a % b;    
  }

  public static void main(String[] args){

  // Object myCalculator (step15)
  Calculator myCalculator = new Calculator();

  // Print output (step16)
  System.out.println(myCalculator.add(5,7));
  // or...
  //int addition - myCalculator.add(5,7);
  //System.out.println(addition);

  System.out.println(myCalculator.subtract(45,11));

  }

}

And here’s the output:

Calculator.java:36: error: illegal character: ‘\u00a0’
public static void main(String args){
^
Calculator.java:36: error: illegal character: ‘\u00a0’
public static void main(String args){
^
Calculator.java:36: error: illegal character: ‘\u00a0’
public static void main(String args){
^
Calculator.java:36: error: illegal character: ‘\u00a0’
public static void main(String args){
^
Calculator.java:36: error: illegal character: ‘\u00a0’
public static void main(String args){
^
Calculator.java:36: error: illegal start of type
public static void main(String args){
^
6 errors

I’m not sure what “illegal character” or “illegal start of type” indicate, please let me know, thanx.

That usually means that after you pasted in the code, one of the whitespace characters is something the compiler can’t handle.
I’m guessing that, in this case, one of the tabs or spaces or newline characters is not something the compiler recognizes.
I had to redo the spaces or other whitespace characters (on the affected lines and possibly the line before or afterward) when I ran into this problem.

2 Likes

Thank you janbazant1107978602, that did it!