I seriously dont know whats wrong with my code


#1


Calculator.java:24: error: illegal start of type
else {
^
Calculator.java:24: error: ';' expected
else {
^
Calculator.java:25: error: illegal start of type
return (a / b);
^
Calculator.java:25: error: expected
return (a / b);
^
Calculator.java:25: error: ';' expected
return (a / b);
^
Calculator.java:25: error: illegal start of type
return (a / b);
^
Calculator.java:25: error: ';' expected
return (a / b);
^
Calculator.java:29: error: class, interface, or enum expected
public int modulo (int a, int b){
^
Calculator.java:31: error: class, interface, or enum expected
System.out.println("Error! Dividing by zero is not allowed.");
^
Calculator.java:32: error: class, interface, or enum expected
return 0;
^
Calculator.java:33: error: class, interface, or enum expected
}
^
Calculator.java:36: error: class, interface, or enum expected
}
^
Calculator.java:40: error: class, interface, or enum expected
public static void main(String[]args){
^
Calculator.java:42: error: class, interface, or enum expected
System.out.println(myCalculator.add(5,7));
^
Calculator.java:43: error: class, interface, or enum expected
System.out.println(myCalculator.subtract(45,11));
^
Calculator.java:45: error: class, interface, or enum expected
}
^
16 errors>


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 int divide (int a, int b) {
  if (b = 0);
  System.out.println("Error! Dividing by zero is not allowed.");
  return 0;
}
  else {
    return (a / b);
  }


public int modulo (int a, int b){
 if (b = 0);
    System.out.println("Error! Dividing by zero is not allowed.");
  return 0;
}
  else{
    return (a % b);
  }



public static void main(String[]args){
Calculator myCalculator = new Calculator();
  System.out.println(myCalculator.add(5,7));
  System.out.println(myCalculator.subtract(45,11));
  
}

}


#2

Check your syntax against the instructions.

Change to,

if (b == 0) {
main(String[] args){

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.