亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

感覺有點奇怪,好像沒有正確使用異常。

package?com.jsdx;

import?java.util.Scanner;
import?java.util.Arrays;

public?class?RentBook?
{
	private?static?String[]?bookName?=?{"悟空傳","斗羅大陸","斗破蒼穹","擇天記","遮天"};
	
	public?RentBook()
	{
		
	}	
	
	public?static?void?main(String[]?args)
	{
		RentBook?rentBook?=?new?RentBook();
		rentBook.select();
	}
	
	public?void?bookNumber()
	{
		System.out.println("輸入圖書序號:");
		@SuppressWarnings("resource")
		Scanner	inNumber?=?new?Scanner(System.in);
		if(inNumber.hasNextInt())
		{
			int?number?=?inNumber.nextInt();
			if(number?>?0?&&?number?<=?bookName.length)
			{
				System.out.println("圖書信息:"?+?bookName[number-1]);
			}
			else
			{
				try?
				{
					System.out.println("沒有該序號圖書!");
					select();
				}?catch?(Exception?e)?
				{
					e.printStackTrace();
				}
			}
		}
		else
		{
			try?
			{
				System.out.println("輸入錯誤,請輸入數字!");
				bookNumber();
			}?catch?(Exception?e)?
			{
				e.printStackTrace();
			}
		}
	}
	
	public?void?inName()
	{
		System.out.println("輸入圖書名稱:");
		@SuppressWarnings("resource")
		String?name?=??new?Scanner(System.in).nextLine();
		boolean?flag?=?Arrays.asList(bookName).contains(name);	
			if(flag)
			{
				System.out.println("圖書信息:"?+?name);
			}
			else
				try?
				{
					System.out.println("沒有該名稱圖書!");
					select();
				}?catch?(Exception?e1)?
				{
					e1.printStackTrace();
				}
	}
	
	public?void?select()
	{
		System.out.println("輸入命令:1-按書名查找圖書;?2-按序號查找圖書");			
		@SuppressWarnings("resource")
		Scanner?inCammond?=?new?Scanner(System.in);
		try
		{
			if(inCammond.hasNextInt())?
			{
				int?cammond?=?inCammond.nextInt();
				if(cammond?==?1)
				{
					inName();
				}
				else?if?(cammond?==?2)
				{
					bookNumber();
				}
				else
				{
					throw?new?CammondException();
				}
			}
			else
			{
				throw?new?CammondException();
			}
		}catch?(CammondException?e)?
		{
			System.out.println("命令無效,請按提示輸入命令!??!");
			select();
		}
	}
}

//CammondException時一般的自定義類型

正在回答

1 回答

我其實都不懂什么是異常

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

感覺有點奇怪,好像沒有正確使用異常。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號