我在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
答案 0 :(得分:2)
System.out.printf("The number of miles traveled each day was: %d %d %d %d", w,x,y,z);