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

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

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

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

慕村225694 2022-10-12 10:19:37
檢查電子郵件地址是否有效。有效的電子郵件地址應(yīng)同時包含 at 符號 (@) 或點 (.)。如果用戶省略了其中任何一個,您的程序必須通知用戶提供的電子郵件不正確,并提示用戶重新輸入電子郵件地址。繼續(xù)重復此步驟,直到用戶提供有效的電子郵件地址。當用戶輸入有效的電子郵件地址時,繼續(xù)執(zhí)行程序的其余部分。- 我們應(yīng)該為此使用循環(huán),但我不確定使用哪個或如何設(shè)置它。我在考慮使用while循環(huá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貢獻1877條經(jīng)驗 獲得超1個贊

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


至于您的while循環(huán)條件,您只想檢查電子郵件地址是否無效。因此,請檢查!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 "."


查看完整回答
反對 回復 2022-10-12
?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

像這樣的東西應(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 

// ...


查看完整回答
反對 回復 2022-10-12
  • 2 回答
  • 0 關(guān)注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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