国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java 注冊后登錄界面程序,異常判斷是否為空等,ArrayList,學生類,集合【詩書畫唱】

2020-05-20 17:00 作者:詩書畫唱  | 我要投稿

制作注冊后登錄界面,使用異常判斷用戶輸入是否為空,輸入內容長度是否大于6位數(shù),密碼是否為空,年齡是否滿18(使用異常制作)




package fuXi;


import java.util.Scanner;


public class yichang {


public static void main(String[] args) {



yonghu yh = new yonghu();



while (true) {


System.out.println("請輸入你的操作:1.登錄? 2.注冊");


Scanner s = new Scanner(System.in);


int num = s.nextInt();


if (num == 1) {


System.out.println("----執(zhí)行登錄操作----");


System.out.println("請輸入用戶名:");


String uname = s.next();


try{


if(uname.length()<6){throw new StringIndexOutOfBoundsException("詩書畫唱提醒你,"


+ "輸入內容長度已經(jīng)小于6");


}



else{System . out. println("輸入內容長度已經(jīng)不小于6,輸入成功!");


}




} catch (StringIndexOutOfBoundsException e) {



System. out. println("詩書畫唱提醒你,輸入內容長度已經(jīng)小于6,為確保你的安全,"


+ "最好大于6位數(shù)!且密碼不能為空!");




}



System.out.println("請輸入你的密碼");


String pwd = s.next();


System.out.println("請輸入你的年齡");


int age = s.nextInt();



try{


if(age<18){throw new Exception("詩書畫唱提醒你,你未滿18歲,不能玩和購買這款游戲!");




}else{System . out. println("詩書畫唱提醒你,年齡設置成功!");}


}


catch (Exception e) {



System. out. println("詩書畫唱警告你,你未滿18歲!");


}





if (uname.equals(yh.uname) && pwd.equals(yh.pwd)&& age ==yh.age) {



System.out.println("登錄成功!");



break;


} else {




System.out.println("登錄失敗,你未注冊,請先注冊 ");


}



} else if (num == 2) {



System.out.println("----執(zhí)行注冊操作----");


System.out.println("請輸入用戶名:");


String uname = s.next();


System.out.println("請輸入你的年齡");


int age = s.nextInt();


try{


if(age<18){throw new Exception("詩書畫唱提醒你,你未滿18歲,不能玩和購買這款游戲!");


}else{System . out. println("詩書畫唱提醒你,年齡設置成功!");}


}


catch (Exception e) {


System. out. println("詩書畫唱警告你,你未滿18歲!");


}


System.out.println("請輸入你的密碼(最好輸入內容長度大于6位數(shù),不能為空)");


String pwd = s.next();


//pwd=null;


try{


if(pwd.length()<6){throw new StringIndexOutOfBoundsException("詩書畫唱提醒你,密碼不能小于6位數(shù)!");


/*拋出異常*/


}



else{System . out. println("詩書畫唱提醒你,密碼設置成功!");}




} catch (StringIndexOutOfBoundsException e) {


System. out. println("詩書畫唱提醒你,輸入內容長度不大于6位數(shù),為確保你的安全,"


+ "必須大于6位數(shù)!且密碼不能為空!");



}




catch (NullPointerException e) {



System. out. println("詩書畫唱提醒你,密碼不能為空!");




}



System.out.println("因為國家法律,要實名認證,請輸入你的真實姓名");



String name = s.next();


yh.uname = uname;


yh.pwd = pwd;


yh.name = name;


yh.age = age;


System.out.println("注冊成功!");


}?


}




}


}


class yonghu {


String uname;


String pwd;


String name;


int age;


}



用ArrayList:創(chuàng)建一個學生類,包含學生編號,姓名,性別,成績,將學生放入類集合中,添加5名學生,算出學生的平均成績





package fuXi;




import java.util.ArrayList;




public class jiHe {




public static void main(String[] arrgs) {




ArrayList s = new ArrayList();




student A1 = new student("點贊編號ID:233", "詩名", '男', 100);




student A2 = new student("點贊編號ID:666", "書名", '男', 100);




student A3 = new student("點贊編號ID:999", "畫名", '男', 100);




student A4 = new student("點贊編號ID:888", "唱名", '男', 100);




student A5 = new student("點贊編號ID:20U(喲)~", "帥名", '男', 100);




s.add(A1);




s.add(A2);




s.add(A3);




s.add(A4);




s.add(A5);




double ChengJiZongHe = 0;




for (int i = 0; i < s.size(); i++) {




student k = (student) s.get(i);




ChengJiZongHe += k.chengji;


}




System.out.println("學生的平均成績:" + ChengJiZongHe / s.size());




}


}




class student {




String ID;




String name;




char sex;




double chengji;




public student(String ID, String name, char sex, double chengji) {




this.ID = ID;




this.name = name;




this.sex = sex;




this.chengji = chengji;




}




}


Java 注冊后登錄界面程序,異常判斷是否為空等,ArrayList,學生類,集合【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
盐津县| 若尔盖县| 体育| 手机| 洪洞县| 涟源市| 太仆寺旗| 六枝特区| 南充市| 黄梅县| 金华市| 峨山| 兴安盟| 康马县| 甘泉县| 贺兰县| 灵武市| 元谋县| 荔波县| 东安县| 天祝| 和政县| 哈巴河县| 扎兰屯市| 武隆县| 库车县| 涟源市| 临邑县| 隆林| 乌兰察布市| 鸡东县| 晋城| 祁东县| 宾阳县| 富平县| 兴安县| 巴林右旗| 横山县| 阿城市| 天峨县| 萝北县|