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

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

使用nextLine時(shí)什么時(shí)候無法接收輸入的行,注釋部分使用nextLine會(huì)出錯(cuò),而next就可以

import java.util.*;


public class findBook {


private String[] bookName={"高數(shù)","英語","C"};

private Scanner input = new Scanner(System.in);

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

findBook bk=new findBook();

while(true){

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

try{

int num=bk.getCommond();

switch(num){

case 1:

bk.name();

break;

case 2:

bk.Number();

break;

case -1:

System.out.println("請輸入指定的數(shù)字");

break;

default:

System.out.println("輸入錯(cuò)誤?。。?);

break;

}

}catch(Exception e){

System.out.println("請重新輸入");

continue;

}

}

}

public int getCommond(){

int num;

try{

num=input.nextInt();

return num;

}catch(Exception e){

input.next();

return -1;

}

}

//按照書名查找

public void name() throws Exception{

String strname;

System.out.print("請輸入書名:");

//input.nextLine();

strname=input.nextLine(); ? ? //如果輸入用nextLine的話就無法接收到輸入???

for(int i=0;i<3;i++){

if(strname.equals(bookName[i])){

System.out.println("找到了"+strname);

return;

}

}

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

}

//按照序號查找

public void Number()throws Exception{

while(true){

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

try{

int index=input.nextInt();

System.out.println("找到了"+bookName[index]);?

}catch(ArrayIndexOutOfBoundsException e){

System.out.println("圖書不存在");

throw new Exception("BookNotExist");

}catch(Exception e){

System.out.println("輸入格式錯(cuò)誤,請根據(jù)提示輸入?。?!");

input.next();

continue;

}

}

}

}


正在回答

2 回答

#1

慕碼人814591 提問者

非常感謝!
2017-05-12 回復(fù) 有任何疑惑可以回復(fù)我~

問題同上!

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

舉報(bào)

0/150
提交
取消

使用nextLine時(shí)什么時(shí)候無法接收輸入的行,注釋部分使用nextLine會(huì)出錯(cuò),而next就可以

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

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

幫助反饋 APP下載

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

公眾號

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