亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復while循環錯誤登錄注銷系統(無數據庫)(還有關于會話時間的代碼)?

如何修復while循環錯誤登錄注銷系統(無數據庫)(還有關于會話時間的代碼)?

喵喵時光機 2022-06-04 10:43:12
我使用為我的學校作業提供的唯一用戶名創建了一個基本的登錄和注銷系統(無數據庫),但我在 while 循環和會話時間方面遇到了問題。我嘗試將一組代碼復制并粘貼到此主代碼的不同部分,以便獲得預期的結果,但結果有點錯誤。我試圖在互聯網上搜索有關會話時間的信息,但一無所獲。  while (login =  true){      try {          System.out.println("Enter your name:");          String name = cue.nextLine();          System.out.println("--------------------");          System.out.println("");          System.out.println("Date and Time of Login:");          System.out.println(dtf.format(now));          System.out.println("");          System.out.println("--------------------");          System.out.println();          System.out.println("Enter your name to log out:");          String logout = cue.nextLine();          System.out.println("");          if (logout.equals(name)){              System.out.println("--------------------");              System.out.println("");              System.out.println("Date and Time of Logout:");              System.out.println(dtf.format(now));              System.out.println("Session Time:");              /*can you also please tell me what code to tell the gap between the               login time and log out time?*/              System.out.println("");              System.out.println("--------------------");              login = false;            } else {                login = true;            }        } catch (Exception e){          cue.nextLine();      } finally{          System.out.println("Do you want to register again? 0 for yes and 1 for no");          int no = cue.nextInt();          if (no==0) {              login = true;          } else if (no==1) {                System.exit(1);          } else {              System.out.println("1 or 0 only!");          }         }}這必須是預期的輸出:如果名稱正確:Enter your name:nmae--------------------Date and Time of login:2019/02/03 16:38:46--------------------Enter your name to log out:nmae--------------------
查看完整描述

2 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

要獲得不同的 beetwen 登錄時間和注銷時間,您可以使用Durationjava8 中的類:


loginTime = LocalDateTime.now();

...

logoutTime = LocalDateTime.now();


Duration.between(loginTime, logoutTime).getSeconds();


查看完整回答
反對 回復 2022-06-04
?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

您正在返回錯誤級別 1,這是程序終止向操作系統返回錯誤的方式。我無法測試是因為我不使用 Windows,但您可以嘗試System.exit(1)System.exit(0).



查看完整回答
反對 回復 2022-06-04
  • 2 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號