Whats wrong with my code?


#1

I cant find any solution for my problem in the internet or here in the forum!

Calculator.java:26: error: incompatible types: unexpected return value
return 0;
^
Calculator.java:28: error: incompatible types: unexpected return value
return num1/num2;
^
Calculator.java:37: error: incompatible types: unexpected return value
return 0;
^
Calculator.java:39: error: incompatible types: unexpected return value
return num1/num2;
^
4 errors


public class Calculator {
  
  public Calculator() {
    
    int num1;
    int num2;
    
  }
  
  public void add(int num1,int num2) {
     
  }
  
  public void subtract(int num1,int num2) {
   
  }
  
  public void multiply(int num1,int num2) {
    
  }
  
  public void divide(int num1,int num2) {
    
 			if (num2==0) {
        System.out.println("Error!");
      	return 0;
      } else {
        return num1/num2;
      }
    
  }
  
  public void modulo(int num1,int num2) {
   
 			if (num2==0) {
        System.out.println("Error!");
      	return 0;
      } else {
        return num1/num2;
      }
    
  }
    
  public static void main(String[] args) {
    
    Calculator myCalculator = new Calculator();
  	
  }
}


#2

On the modulo method you used the divide symbol. Modulo does divide, but it returns the remainder as your answer. Divide returns the total value after dividing.

ex. 9 / 5 = 1.8

ex. 9 % 5 = 4 When you do your division of 9 % 5 your can put 5 into 9 only one time, then your remainder is 4 which is your answer.

Modulo and divide are not the same so for modulo use the % symbol.


#3

Oh, I missed that! But the errors are still the same!


#4

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