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

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

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

package?com.imooc.test;

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

public?class?Exercise?{
	
	private?static?String[]?books?=?{"Java編程思想",?"C語言程序設(shè)計",?"微積分",?"數(shù)據(jù)結(jié)構(gòu)",?"計算機科學(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-按照名稱查找圖書;2-按照序號查找圖書");
		try?{
			int?index?=?in.nextInt();
			switch?(index)?{
			??case?1?:
				??System.out.println("輸入圖書名稱:");
				??String?name?=?in.next();
				??for?(?String?s?:?Exercise.books)?{
					??if?(?s.equals(name)?)?{
						??System.out.println("book:"+name);
						??return;
					??}
				??}
				??System.out.println("圖書不存在!");
				??method();
				??break;
			??case?2:
				??System.out.println("輸入圖書序號:");
				??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("圖書不存在!");
					??method();
				??}?catch?(?Exception?e?)?{
					??System.out.println("命令輸入錯誤!請根據(jù)提示輸入數(shù)字命令!");
					??method();?
				??}
				??break;
			}
		}?catch?(?InputMismatchException?input?)?{
			System.out.println("命令輸入錯誤!請根據(jù)提示輸入數(shù)字命令!");
			method();
		}
	}
}


正在回答

3 回答

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

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

恩,不錯不錯

可以將switch抽取出來成為一個單獨的方法,哈哈哈

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

圖書圖書序號就是其索引號+1,沒設(shè)計Book類,肯定是不夠的,但運行足以滿足題目需求。

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

舉報

0/150
提交
取消

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

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

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

幫助反饋 APP下載

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

公眾號

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