7 errors in the main method - need help


#1

hello everyone!
i really cant see the problem - can any1 help me?

Calculator.java:40: error: illegal start of expression
public static void main (String[] args) {
^
Calculator.java:40: error: illegal start of expression
public static void main (String[] args) {
^
Calculator.java:40: error: ';' expected
public static void main (String[] args) {
^
Calculator.java:40: error: '.class' expected
public static void main (String[] args) {
^
Calculator.java:40: error: ';' expected
public static void main (String[] args) {
^
Calculator.java:42: error: ';' expected
System.out.println(myCalculator.add(5, 7))
^
Calculator.java:44: error: reached end of file while parsing
}
^
7 errors

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 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))
    myCalculator.subtract(45, 11);
  }   
}


#2

You need to close the method modulo with a brace: }.

It is telling you that public is an illegal start of an expression -- which is true, because it's still reading the modulo method and is unsure why you are using that keyword inside of a method. The seven errors are simply Java complaining about not being able to read the file, but the main error is that you haven't closed out that method.

Good luck!


#3

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