私はJavaを学んでいて、同じクラスのメインメソッド内の非静的メソッドにアクセスする方法(ある場合)を見つけるのに役立つ簡単なプログラムを作成しようとしていました。これは私がこれまでに持っているものです
import java.util.Scanner;
public class MethodVariables
{
public int num1;
public int num2;
public int add = (num1 + num2);
public int sub = (num1 - num2);
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.println("Please enter the first number: ");
String num1 = input.nextLine();
System.out.println("Please enter the second number: ");
String num2 = input.nextLine();
input.close();
// I know these wouldn't work this way but this is just to show what I am trying to accomplish
addition(add);
subtraction(sub);
}
public void addition(int add)
{
System.out.println("The sum of the two is: " +add);
}
public void subtraction(int sub)
{
System.out.println("The diference of the two is: "+sub);
}
}
私が見落としていることを誰かが知っていれば、助けていただければ幸いです。