日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

第三章第三十题(当前时间)(Current time)

發布時間:2024/1/1 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第三章第三十题(当前时间)(Current time) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第三章第三十題(當前時間)(Current time)

  • *3.30(當前時間)修改編程練習題2.8,以12小時時鐘制顯示小時數。
    下面是一個運行示例:
    Enter the time zone offset to GMT:-5
    The current time is 4:50:34 AM

    *3.30(Current time) Revise Programming Exercise 2.8 to display the hour using a 12-hour clock.
    Here is a sample run:
    Enter the time zone offset to GMT:-5
    The current time is 4:50:34 AM

  • 參考代碼:

package chapter03;import java.util.Scanner;public class Code_30 {public static void main(String[] args) {int ZoneOffset;long CurrHours,CurrMinutes,CurrSeconds;long CurrentMilliSeconds;CurrentMilliSeconds = System.currentTimeMillis();CurrSeconds = CurrentMilliSeconds / 1000 % 60;CurrMinutes = CurrentMilliSeconds / 1000 / 60 % 60;CurrHours = CurrentMilliSeconds / 1000 / 60 / 60 % 24;System.out.print("Enter the time zone offset to GMT : ");Scanner ZoneOffsetInput = new Scanner(System.in);ZoneOffset = ZoneOffsetInput.nextInt();CurrHours = (CurrHours + ZoneOffset + 24) % 24;if(CurrHours <= 12)System.out.println("The current time is "+ CurrHours + ":" + CurrMinutes + ":" + CurrSeconds + " AM");else{CurrHours %= 12;System.out.println("The current time is "+ CurrHours + ":" + CurrMinutes + ":" + CurrSeconds + " PM");}ZoneOffsetInput.close();} }
  • 結果顯示:
Enter the time zone offset to GMT : 8 The current time is 11:15:40 AMProcess finished with exit code 0

總結

以上是生活随笔為你收集整理的第三章第三十题(当前时间)(Current time)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。