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.