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

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

課后作業(yè)——這是我寫(xiě)的代碼,大家可以看看!

package?com.imooc.test;

import?java.util.InputMismatchException;
import?java.util.Scanner;

public?class?Exercise?{
	
	private?static?String[]?books?=?{"Java編程思想",?"C語(yǔ)言程序設(shè)計(jì)",?"微積分",?"數(shù)據(jù)結(jié)構(gòu)",?"計(jì)算機(jī)科學(xué)導(dǎo)論"};
	
	public?static?void?main(String[]?args)?{
		
???????Exercise?exercise?=?new?Exercise();
???????exercise.method();
	}
	
	public?void?method()?{
		Scanner?in?=?new?Scanner(System.in);
		System.out.println("輸入命令:1-按照名稱查找圖書(shū);2-按照序號(hào)查找圖書(shū)");
		try?{
			int?index?=?in.nextInt();
			switch?(index)?{
			??case?1?:
				??System.out.println("輸入圖書(shū)名稱:");
				??String?name?=?in.next();
				??for?(?String?s?:?Exercise.books)?{
					??if?(?s.equals(name)?)?{
						??System.out.println("book:"+name);
						??return;
					??}
				??}
				??System.out.println("圖書(shū)不存在!");
				??method();
				??break;
			??case?2:
				??System.out.println("輸入圖書(shū)序號(hào):");
				??try?{
					??int?num?=?in.nextInt();?
					??for?(?String?s?:?Exercise.books)?{
						??if?(?s.equals(Exercise.books[num-1]))?{
							??System.out.println("book:"+Exercise.books[num-1]);
							??return;
						??}
					??}
					??System.out.println("圖書(shū)不存在!");
					??method();
				??}?catch?(?Exception?e?)?{
					??System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!");
					??method();?
				??}
				??break;
			}
		}?catch?(?InputMismatchException?input?)?{
			System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!");
			method();
		}
	}
}


正在回答

3 回答

第26行代碼for循環(huán)里的是什么意識(shí)啊,求解釋

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

恩,不錯(cuò)不錯(cuò)

可以將switch抽取出來(lái)成為一個(gè)單獨(dú)的方法,哈哈哈

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

圖書(shū)圖書(shū)序號(hào)就是其索引號(hào)+1,沒(méi)設(shè)計(jì)Book類,肯定是不夠的,但運(yùn)行足以滿足題目需求。

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

舉報(bào)

0/150
提交
取消

課后作業(yè)——這是我寫(xiě)的代碼,大家可以看看!

我要回答 關(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)