java - 如何在输出中获取输入词?开始 Java
问题描述
我试图在我的输出中找到出发地,但我对如何去做感到困惑。我必须在顶部的 String 方法中声明它吗?
int seconds1;
int seconds2;
int minutes;
int hours;
Scanner sc = new Scanner(System.in);
System.out.println("Enter departure city: ");
String departure = sc.nextLine();
System.out.println("Enter arrival city ");
String arrival = sc.nextLine();
System.out.println("Enter time (in seconds) it takes to travel between: ");
seconds1 = sc.nextInt();
hours = (seconds1 % 86400) / 3600;
minutes = ((seconds1 % 86400) % 3600) / 60;
seconds2 = ((seconds1 % 86400) % 3600) % 60;
// I am trying to get this to say "The time between + departure + and + arrival+is"
System.out.println("The time to travel between and is ");
System.out.println(hours + " : " + minutes + " : " + seconds2);
}
}
解决方案
你会有这个:
System.out.println("The time to travel between " + departure + " and " + arrival + " is ");