第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我的 Java 代碼“if 語(yǔ)句”出現(xiàn)不需要的輸出(標(biāo)題太長(zhǎng),無(wú)法描述)

我的 Java 代碼“if 語(yǔ)句”出現(xiàn)不需要的輸出(標(biāo)題太長(zhǎng),無(wú)法描述)

慕的地8271018 2024-01-05 15:14:11
編輯:添加更多代碼(對(duì)java非常陌生,我沒(méi)有任何教科書(shū)。我正在根據(jù)我在網(wǎng)上找到的內(nèi)容拼湊它是如何工作的,請(qǐng)友善。)我正在嘗試為我在大學(xué)的 Java 課程制作一個(gè)“時(shí)間計(jì)算器”。(這是我們的任務(wù))。我必須像這樣輸出:(天)HH:MM:SS。如果沒(méi)有“天”,則為 HH:MM:SS,如果沒(méi)有“小時(shí)”,則為 MM:SS,依此類(lèi)推。然而,在我的代碼中,我的 if 語(yǔ)句只有幾秒鐘,沒(méi)有分鐘、小時(shí)或天,因此無(wú)法正確執(zhí)行。如果我輸入 40 秒,它將輸出:0:00:40 小時(shí)。我該如何解決?我知道 If/If else 語(yǔ)句有問(wèn)題。我試圖通過(guò)輸入 1-60 之間的各種數(shù)字來(lái)找出問(wèn)題,但它總是返回“0:00:(1-60) 小時(shí)”。我不知道從哪里開(kāi)始解決這個(gè)問(wèn)題。final int x = 9;final int n_Days;final int n_Hours;final int n_Minutes;final int n_Seconds;n_Days = total_seconds / 86400;n_Hours = (total_seconds % 86400 ) / 3600;n_Minutes = ((total_seconds % 86400 ) % 3600 ) / 60;n_Seconds = ((total_seconds % 86400 ) % 3600 ) % 60;if (n_Days == 0) {    if (n_Minutes < x || n_Seconds < x) {    String padded = String.format("%02d" , n_Minutes);    String padded2 = String.format("%02d" , n_Seconds);    System.out.print("You entered " + total_seconds + " seconds, which is " + n_Hours + " hours, " + n_Minutes + " minutes, and " +  n_Seconds + " seconds.");    System.out.print("\n");    System.out.print(n_Hours + ":" + padded + ":" + padded2 + " hours.");    }}else if (n_Days == 0 && n_Hours == 0) {    if (n_Minutes < x || n_Seconds < x) {    String padded = String.format("%02d" , n_Minutes);    String padded2 = String.format("%02d" , n_Seconds);    System.out.print("You entered " + total_seconds + " seconds, which is " + n_Minutes + " minutes, and " +  n_Seconds + " seconds.");    System.out.print("\n");    System.out.print(padded + ":" + padded2);        }}else if (n_Days == 0 && n_Hours == 0 && n_Minutes == 0) {    System.out.print("You entered " + total_seconds + " seconds, which is " +  n_Seconds + " seconds.");    }    }}如果我輸入的總秒數(shù)小于 60,那么我希望第二個(gè)“else-if”語(yǔ)句像這樣執(zhí)行:“你輸入了30秒,就是30秒。”
查看完整描述

1 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

if (n_Days == 0)

這是你的第一個(gè)if聲明。如果n_Days0,它將被執(zhí)行,而且最重要的是 -else語(yǔ)句永遠(yuǎn)不會(huì)被執(zhí)行。因此, if n_Daysis0n_Hoursis 0tooif (n_Days == 0)都會(huì)被執(zhí)行,并且else if...- 語(yǔ)句將被跳過(guò)。

您只需更改語(yǔ)句的順序 - 或嵌套它們 - 就可以了。


查看完整回答
反對(duì) 回復(fù) 2024-01-05
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)