Basic calculator error

hi I am trying to run my basic calculator app and I keep getting this error
Calculator.java:21: error: expected
public int modulo(a % b){
^
1 error

this is the code below
/* this is a calculator app*/

public class Calculator{

public Calculator(){

}

public int add(int a , int b){

return a + b;

}

public int subtract(int a, int b){

return a - b;

}

public int multiply(int a, int b){

return a * b;

}

public double divide (int a, int b){

return a / b;

}

public int modulo(a % b){

return a % b;

}

public static void main(String args){

calculator myCalculator = new Calculator();

}

public class Calculator{

public Calculator(){

System.out.println(myCalculator.add(5,7));

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

}

}

}

When defining a function, you use the following template:

{protection level(public, etc} {static/not static} {return type} {name} ({parameter type} {parameter name}

So, it might look like:

public int 4(int param1){
//code
}

Have a look at this line:

Does it follow the function declaration template?

2 Likes

thank you very much for your help, I just went over the exercise again and realized my mistakes, the code runs now.

1 Like