Im getting a stack overflow when executing my calculator - help required


#1


https://www.codecademy.com/en/courses/learn-java/projects/basic-calculator

I get a stackoverflow with the calculatorexercise, can anyone explain why?

public class Calculator {
  
  Calculator myCa = new Calculator ();
  
  public int add(int a, int b) {
    return a + b;
    }
  public int substract(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 myCa = new Calculator ();
    
 System.out.println( myCa.add(5, 7));
 System.out.println( myCa.substract(45, 11));

  
                                  
                                  }
}


#2

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