package com.imooc;
import java.util.*;
/*定義字符串數(shù)組保存圖書信息
*提示用戶分別按 書名和圖書序號查找圖書
*
*/
public class Book {
public static void main(String[] args) {
boolean x;
String[] book=new String[3];
book[0]="英語";
book[1]="論語";
book[2]="高數(shù)";
System.out.print("輸入命令方式:1——按照書名查找圖書; 2——按照書序號查找圖書 ");
Scanner input=new Scanner(System.in);
int fangshi=input.nextInt();
if(fangshi==1){
System.out.println("---書名查找圖書---");
}else if(fangshi==2){
System.out.println("——圖書序號查找圖書——");
}
Scanner incan=new Scanner(System.in);
int xuhao=incan.nextInt();
String name=incan.nextLine();
try{
}catch(InputMismatchException i ){
System.out.println("命令輸入錯誤!請根據(jù)提示輸入數(shù)字命令");
}
try 里面填什么,呢?
2014-08-04
哦,,謝謝啦,
2014-08-04
int xuhao=incan.nextInt(); 可以把這句放在try 里,當用戶輸入的數(shù)據(jù)不能轉(zhuǎn)換為整數(shù)時,就會拋出異常啦