我正在用 Java 编码,我必须创建一个接受用户输入的程序,我已经完成了。但是我很困惑我可以使用什么语句来列出用户输入的那些整数。
这是我到目前为止所拥有的:
//Biker's Journey Program
import java.util.Scanner;
public class lab2
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in);
int w;
int x;
int y;
int z;
int result;
System.out.print("Please enter the first day's traveled miles: ");
w = input.nextInt();
System.out.print("Please enter the second day's traveled miles: ");
x = input.nextInt();
System.out.print("Please enter the third day's traveled miles: ");
y = input.nextInt();
System.out.print("Please enter the last day's traveled miles: ");
z = input.nextInt();
System.out.print("The number of miles traveled was: ");
System.out.println()
result = (w + x + y + z) / 4;
System.out.printf("The average miles per day traveled is %d\n", result);
}
}
这段代码进行了计算,我只是不知道如何获得像这张图片这样列出的整数:http: //imgur.com/KFNkWEd