我試圖在我的輸出中找到出發(fā)地點(diǎn),但我對(duì)如何去做感到困惑。我是否必須在頂部的 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貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以指定departure
和arrival
變量,System.out.println()
如下面的代碼所示:
System.out.println("The time to travel between"+departure +" and"+arrival +" is ");

揚(yáng)帆大魚(yú)
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
你會(huì)有這個(gè):
System.out.println("The time to travel between " + departure + " and " + arrival + " is ");
添加回答
舉報(bào)
0/150
提交
取消