This is the main class
public static void main(string[] args) { scanner keyboard = new scanner (system.in); int number1; int number2; int result = 0; system.out.println("enter the first number"); number1 = keyboard.nextint(); system.out.println("enter the second number"); number2 = keyboard.nextint(); result = adder(number1, number2); system.out.println(result); keyboard.close(); } }
This is the method class
package Relearn; public class methodology { public static int adder(int number1, int number2) { int num1 = number1; int num2 = number2; int sum = num1 + num2; return sum; } }
I have "adder" in the main class which is private instead of public and it works fine to put two variables together and when I move it to another class it does nothing does, just gives me the error on line 14 [Exception in thread "main" java.lang.error: Unresolved compilation issues: For type testers, method adder(int, int) is undefined In relearn.tester.main(tester.java:14)]
I found some errors.
import Relearn.methodology;
Then call methodology.adder(number1, number2);
import static Relearn.methodology.adder;
- You don't need to change anything in this case. The above is the detailed content of Trying to write a simple addition program, why doesn't the main class recognize the 'adder' method?. For more information, please follow other related articles on the PHP Chinese website!