嘿,我是 Java 编程的新手,我正在努力改变变量并寻求一些帮助。问题如下:
创建一个程序,要求用户输入三个数字,然后打印它们的总和。在您的程序中使用以下结构:
// TODO code application logic here
Scanner reader = new Scanner(System.in);
int sum = 0;
int read;//`enter code here`
// WRITE YOUR PROGRAM HERE
// USE ONLY THE VARIABLES sum, reader AND read!
System.out.println("Sum: " + sum);
这是我在下面写的,当然我遇到了语法错误:
Scanner reader = new Scanner(System.in);
int sum = 0;
System.out.print("Type the first Number: ");
int read = Integer.parseInt(reader.nextLine());
System.out.print("Type the second number: ");
int read = read + (Integer.parseInt(reader.nextLine()));
System.out.print("Type the third number: ");
int read = read + (Integer.parseInt(reader.nextLine()));
sum = read;
System.out.println("Sum: " + sum);