Idk why this Java code errors

public class HelloWorld{

     public static void main(String []args){
       
        int x = 5;
        int c = 6;
        return x += c;
        
     }  
}

when I execute the code, the error message prints out -
“HelloWorld.java:7: error: incompatible types: unexpected return value
return x += c;”

I am trying to execute a code that adds X + C with the += as the operator but it doesn’t work.

The main method doesn’t return a value (hence the void in the signature). So you will get this message anytime you try to return a value in main.

so I need a function for this to work. I am guessing something along the lines of

public class HelloWorld{
       public static myMethod(int x, int y) {
        return x += y;
        }
       public static void main(String []args){
         System.out.println(myMethod(5, 6));
     }  
}

ops I figured out that I errored in the modifiers with “public static myMethod”
it should be static int but IDK why you can’t declare public and why you need to add “int” as a type identifier when the data (int x, int y) already identifies it later down the parameters.