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

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

使用循環(huán)確定電子郵件地址是否包含 2 個(gè)字符

使用循環(huán)確定電子郵件地址是否包含 2 個(gè)字符

慕村225694 2022-10-12 10:19:37
檢查電子郵件地址是否有效。有效的電子郵件地址應(yīng)同時(shí)包含 at 符號(hào) (@) 或點(diǎn) (.)。如果用戶省略了其中任何一個(gè),您的程序必須通知用戶提供的電子郵件不正確,并提示用戶重新輸入電子郵件地址。繼續(xù)重復(fù)此步驟,直到用戶提供有效的電子郵件地址。當(dāng)用戶輸入有效的電子郵件地址時(shí),繼續(xù)執(zhí)行程序的其余部分。- 我們應(yīng)該為此使用循環(huán),但我不確定使用哪個(gè)或如何設(shè)置它。我在考慮使用while循環(huán)?我們不能使用我在這里看到人們使用的正則表達(dá)式方法,因?yàn)槲覀冞€沒有學(xué)到這一點(diǎn)。This is the code that we have to update(we are now supposed to use a loop to continue asking the user for email address until both characters are used, instead of exiting the program):if(emailAddress.contains("@")){     //prompt user for major & classification code    System.out.print("\nPleast enter two characters (Character #1: Major Code and Character #2: Classification Code): ");    } else{     //exit program if no '@' symbol in email address    System.out.print("\nYou have entered an invalid email address.");    System.out.println("\n\nGoodbye!");    System.exit(0);}
查看完整描述

2 回答

?
冉冉說

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

我建議使用while循環(huán)。當(dāng)for您知道需要重復(fù)操作多少次時(shí),循環(huán)是最好的,但while循環(huán)適用于重復(fù)未知次數(shù)。它可以運(yùn)行 0 到多次。


至于您的while循環(huán)條件,您只想檢查電子郵件地址是否無效。因此,請(qǐng)檢查!emailAddress.contains("@")它是否不包含@,!emailAddress.contains(".")如果不包含.。


您可以使用||來查看任一條件是否為真。


// Prompt the user

System.out.println("Please enter an email address");


String emailAddress =  // read in their email adress 


while(!emailAddress.contains("@") || !emailAddress.contains(".")) {

    System.out.println("You have entered an invalid email address, please enter another.");


    emailAddress = // read in their email address again

}


// Email address now contains "@" and "."


查看完整回答
反對(duì) 回復(fù) 2022-10-12
?
喵喔喔

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

像這樣的東西應(yīng)該工作:


// While email does not contain the two characters..

// Keep asking the user to enter the correct email.

while(!emailAddress.contains("@") || !emailAddress.contains(".")){ 

    System.out.print("\nYou have entered an invalid email address.");

    // Add line of code here to ask for email address.

    // Update emailAddress of course

}

//prompt user for major & classification code

System.out.print("\nPleast enter two characters (Character #1: Major Code and Character #2: Classification 

// ...


查看完整回答
反對(duì) 回復(fù) 2022-10-12
  • 2 回答
  • 0 關(guān)注
  • 155 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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