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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

交作業(yè)了,萌新求指教。

package mytest;


import java.util.Scanner;


public class Hdl {

static String s[]=new String[]{"高數(shù)","大學(xué)英語","政治","java"};

public static void main(String[] args) {

// TODO 自動生成的方法存根

Choose();

}

public static void Choose(){

System.out.println("輸入命令:1—按照名稱查找圖書;2-按照序號查找圖書");

try{

Scanner sc=new Scanner(System.in);

? ? int i=sc.nextInt();

? ? if(i==1){

System.out.println("輸入圖書名稱:");

tushu();

}else if(i==2){

System.out.println("請輸入序號:");

xuhao();

}else {

System.out.println("輸入的命令有誤,請根據(jù)提示輸入數(shù)字!");

Choose();

}

? ? }catch(Exception e){

? ? ?

? ? }

}

public static void tushu(){

try{

Scanner a=new Scanner(System.in);

? ? String x=a.nextLine();

? ? Name(x);

? ? ? ? if(x.equals(s[0])){

System.out.println("book:"+s[0]);}

else if(x.equals(s[1])){

System.out.println("book:"+s[1]);}

else if(x.equals(s[2])){

? ? ? ? ? ? System.out.println("book:"+s[2]);}

else if(x.equals(s[3])){

? ? ? ? ? ? ? ? ? ? ?System.out.println("book:"+s[3]);

}

}catch(Exception e){

System.out.println(e.getMessage());

Choose();

}

}

public static void xuhao(){

try{

Scanner b=new Scanner(System.in);

? ? int y=b.nextInt();

? ? Number(y);

if(y==1){

System.out.println("book:"+s[0]);}

else if(y==2){

System.out.println("book:"+s[1]);}

else if(y==3){

? ? ? ? ? ? System.out.println("book:"+s[2]);}

else if(y==4){

? ? ? ? ? ? ? ? ? ? ?System.out.println("book:"+s[3]);

? ? }


}catch(Exception e){

System.out.println(e.getMessage());

Choose();

}

}

public static String Name(String x)throws Exception{

if(!(x.equals(s[0]))&&!(x.equals(s[1]))&&!(x.equals(s[2]))&&!(x.equals(s[3]))){

throw new Exception("圖書不存在");

}

return x;

}

public static int Number(int y)throws Exception{

if(y<1^y>4){

throw new Exception("圖書不存在");

}

return y;

}

}


正在回答

1 回答

我碰巧看到了,那我就指出一下美中不足的地方吧,首先源碼缺乏對于輸入輸出流的關(guān)閉,其次呢if?else過多,如果能夠?qū)⒋罅康膇f?else都用異常來處理就好了。然后呢,關(guān)于字符串匹配好像可以用現(xiàn)成的庫方法調(diào)用

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

交作業(yè)了,萌新求指教。

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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