求任意两个给定整数的和

Find the sum of any two given integers

[https://i.stack.imgur.com/1IRVE.png][1]我想通过多种方法解决这个问题。但我无法解决这个问题。我创建了两种方法(一种方法是从用户那里获取输入并执行加法,另一种方法是执行执行加法的逻辑),我还通过 [https://i.stack.imgur.[= 传递了参数19=].png][2]h 两种方法.

问题:

C:\Users\souvi\Desktop\myProgrammingWorld\JAVA\MyProgrammingWorld\src\BasicJavaProgram.java:7:9

java: class BasicJavaProgram 中的 takingInput 方法不能应用于给定类型; 要求:整数,整数 发现:没有参数 原因:实际和形式参数列表的长度不同

包 com.apnacollege;

导入java.util.Scanner;

public class 执行加法 {

private static int num1;
private static int num2;

public static void main(String[] args) {
    
    whatToDo();
    takingInputsForUsers();
    System.out.println("The answer is : " + calculateSum());
}

static void whatToDo() {
    
    System.out.print("Enter any two positive integers to perform adition : ");
}

static void takingInputsForUsers() {
    
    Scanner scan = new Scanner(System.in);
    num1 = scan.nextInt();
    num2 = scan.nextInt();
    scan.close();
}

static int calculateSum() {
    
    int sum = num1 + num2;
    return sum;
}

}

点击link--Here is my answer, I have solved my issue