为了账号安全,请及时绑定邮箱和手机立即绑定

如何在输出中获取输入词?初学Java

如何在输出中获取输入词?初学Java

元芳怎么了 2021-09-29 13:39:51
我试图在我的输出中找到出发地点,但我对如何去做感到困惑。我是否必须在顶部的 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);  }}
查看完整描述

3 回答

?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

您可以指定departurearrival变量,System.out.println()如下面的代码所示:

System.out.println("The time to travel  between"+departure +" and"+arrival +"  is ");


查看完整回答
反对 回复 2021-09-29
?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

你会有这个:

System.out.println("The time to travel between " + departure + " and " + arrival + " is ");



查看完整回答
反对 回复 2021-09-29
  • 3 回答
  • 0 关注
  • 151 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信