打印用于描述两个数相加的公式

Print the formula used to describe the addition of two numbers

我卡在了 U of Helsinki Java MOOC:

Create a program that can be used to add two integers together. In the beginning, the user is asked to give two integers that are to be summed. The program then prints the formula that describes the addition of the numbers.

Example output:

Give the first number:
5
Give the second number:
4
5 + 4 = 9

我正在尝试让系统打印““第一”+“第二”是“结果”。出于某种原因,我对这个原本简单的问题感到困惑。我的代码总是抛出错误。我是什么最后一行做错了吗?

import java.util.Scanner;

public class AdditionFormula {

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    // write your program here
    System.out.println("Give the first number: ");
    int first = Integer.valueOf(scanner.nextLine());
    
    System.out.println("Give the second number: ");
    int second = Integer.valueOf(scanner.nextLine());
    
    //System.out.println("first" " + " Integer.valueOf(first) + Integer.valueOf(second));
    System.out.println(first + " + " + second " = " + (first + second));
}

您提供的代码无法编译

改为

System.out.println(first + " + " + second + " = " + (first + second));