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

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

圖書名字判斷不了啊

因?yàn)槠鶈?wèn)題我就只把執(zhí)行相關(guān)的部分貼出來(lái):

static String tushu[]={"論語(yǔ)","高數(shù)","數(shù)據(jù)結(jié)構(gòu)","單片機(jī)應(yīng)用","JAVA入門"}; //這部分是數(shù)組的代碼


case "1":

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

String name=s.nextLine();

name=name.trim();

System.out.println(tushu[0]);

for(int i=0;i<tushu.length;i++){

if(tushu[i]==name){

System.out.println("book:"+name);

break;

}//這不部分是選擇圖書名稱匹配的代碼 ? 就是這里判斷不出來(lái)。輸出什么都試過(guò)了,就是進(jìn)不了這個(gè)循環(huán)

if(i==(tushu.length-1)){

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

}

}

break;


正在回答

3 回答

字符串對(duì)比 需要用到equals ???if(tushu[i]==name)你這句改成??if(tushu[i].equals(name))

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

qq_老表_1 提問(wèn)者

非常感謝!
2016-03-24 回復(fù) 有任何疑惑可以回復(fù)我~

說(shuō)錯(cuò)了,是那個(gè)if判斷進(jìn)不去

0 回復(fù) 有任何疑惑可以回復(fù)我~
package?模擬借書系統(tǒng);

import?java.util.Scanner;


public?class?BorrowBooks?{

	static?String?tushu[]={"論語(yǔ)","高數(shù)","數(shù)據(jù)結(jié)構(gòu)","單片機(jī)應(yīng)用","JAVA入門"};
	public?static?void?main(String[]?age){
		boolean?cc=true;
		while(cc){
			try?{
			System.out.println("輸入命令:1-按照名稱查找圖書:2-按照標(biāo)號(hào)查找圖書");		
			Scanner?s=?new?Scanner(System.in);	
			String?a=s.nextLine();
			switch?(a)?{
			case?"1":
				System.out.println("輸入圖書名稱:");
				String?name=s.nextLine();
				name=name.trim();
				System.out.println(tushu[0]);
				for(int?i=0;i<tushu.length;i++){					
					if(tushu[i]==name){//這個(gè)循環(huán)進(jìn)不去
						System.out.println("book:"+name);
						break;
					}
					if(i==(tushu.length-1)){
						throw?new?NullPointerException("圖書不存在");
					}
				}
				break;

			case?"2":
				System.out.println("請(qǐng)輸入圖書編號(hào):");
				String?text=s.nextLine();
				int?n=Integer.parseInt(text);
				System.out.println("book:"+tushu[n-1]);
				break;
			
			default:
				throw?new?typeException("輸入命令錯(cuò)誤,請(qǐng)按要求輸入命令");
			}
			cc=false;


		}?catch?(typeException?e)?{
			//?TODO?自動(dòng)生成的?catch?塊
			System.out.println("輸入命令錯(cuò)誤,請(qǐng)按要求輸入命令!");
		}catch(NullPointerException?e){
			System.out.println("圖書不存在!");
		}catch(NumberFormatException?e){
			System.out.println("請(qǐng)按要求輸入數(shù)字!");
		}
		}
		
		
	}

	
}

class?typeException?extends?Exception?{
	/**
	?*?
	?*/
	private?static?final?long?serialVersionUID?=?1L;
	public?typeException(){};
	public?typeException(String?a){
		super(a);
	}
}

全部貼出來(lái) 大家看看哪里有問(wèn)題啊

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

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409774    人
  • 解答問(wèn)題       4546    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過(guò)的精彩,快來(lái)加入吧

進(jìn)入課程

圖書名字判斷不了啊

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

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

幫助反饋 APP下載

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

公眾號(hào)

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