package rentbook;import java.util.Scanner;public class text {?? public? static Scanner scan=new Scanner(System.in);?? public? static book[] bo={?? ??? ??? ?new book("高數(shù)"),?? ??? ??? ?new book("物理"),?? ??? ??? ?new book("語文"),?? ??? ??? ?new book("英語"),?? ??? ??? ?new book("c語言")?? ???? };?? ??? ?public static void main(String[] args) {?? ??? ?// TODO Auto-generated method stub????? while (true ){?? ??? ?? System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");????????? int inputnum=inputnum1();????????? switch(inputnum){????????? case 1 : System.out.println("按照名稱查找圖書");?????????????????? inputname();?????????????????? break;????????? case 2: System.out.println("按照序號查找圖書");????????????????? System.out.println("請輸入序號"); ???????? ??? ??? ??? ?try{???????? ??? ??? ??? ??? ?int putnum=inputnum1();???????? ??? ??? ??????? System.out.println(bo[putnum-1]);???????? ??? ??? ??? ?}catch(Exception e){???????? ??? ??? ??? ??? ?scan=new Scanner(System.in);???????? ??? ??? ??? ??? ?System.out.println("您輸入的數(shù)字過大");???????? ??? ??? ??? ?}???????? ??? ??? ??? ?break;????????? case -1 : System.out.println("請輸入數(shù)字");break;????????? default: System.out.println("輸入的數(shù)字不存在");continue;????????? }????? }?? ?}?? ?private static void inputname() {?? ??? ?// TODO Auto-generated method stub?? ??? ?System.out.println("請輸入書名");?? ??? ?String input=scan.nextLine();?? ??? ?try{?? ??? ??? ?for(int i=0;i<bo.length;i++){?? ??? ??? ??? ?if(input.equals(bo[i].name))?? ??? ??? ??? ?System.out.println(bo[i].name);?? ??? ??? ?}?? ??? ?}catch(Exception e){?? ??? ??? ?scan=new Scanner(System.in);?? ??? ??? ?System.out.println("請輸入正確的書名");?? ??? ?}}?? ?private static int inputnum1() {?? ??? ?// TODO Auto-generated method stub?? ??? ?int a=scan.nextInt();?? ??? ?try{?? ??? ??? ?return a;?? ??? ?}catch(Exception e){?? ??? ??? ?scan=new Scanner(System.in);?? ??? ???? return -1;?? ??? ?}?? ?}}
如下代碼加黑部分為什么自動賦值為0了,而沒有提示輸入?
qq_什么亡魂溺海沒有跳海實在_03283094
2016-11-27 22:36:54