为什么加了个while(bl)和try catch就可以重新输了?输入的时候图书名称打错
package com.imooc;import java.util.Scanner;public class Book { static String[] name={new String("大学"),new String("中庸"), new String("论语"),new String("孟子")}; static int[] num={1,2,3,4}; public static void main(String[] args) { System.out.println("1-按照名称查找图书;2-按照序号查找图书"); Scanner input=new Scanner(System.in); int score=input.nextInt(); boolean bl=true; while(bl){ try{ while(score==1){ System.out.println("输入图书名称"); String bookname = input.next(); int i=0; if(bookname.equals(name)){ System.out.println("book:"+name); bl=false; i++; break; } } while(score==2){ System.out.println("输入图书序号"); int booknum=input.nextInt(); if(booknum==num[booknum-1]){ System.out.println("book:"+name[booknum-1]); bl=false; break; } } }catch(Exception e){ System.out.println("图书不存在,请重新输入"); } } }} |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
ZCFOSBKGQSI
NKMQMIFVRND
DZHKNQGAEGW
RNPZPFCSUEV
KZVLIFVYHXT
DNQTXLUYAYB
CLORHXOQAJT
WFHFBLHKHQM
QADGQNPQGXG
AKRAQHJTWTV
FUDGWTJGDMB
AWMVQOXNDTC
WMCTCZUKFWZ
MPFVGKADYVL
AJZXZWZJZJZ
RMJTPMWMPYO
QMVYNXZPSOS
DMISIMOXHDA
WYVFOENJMCF
XNWGVGPQAJZ
AKUWMVYOEAK
XSILVFBEASV
SBDGKBLIEIY
CYAECLUEAXN
XDDXTTJXHUE
PLAEUVSISIY
LBKUWFVYIRU
CMVTJHRTWHK
XYASBRBENXN
RAJMVEAXZWZ
XMJZCLTJMWT
KUKZBXNCMVL
SGBOUHIPVUT
UKVFCSPLTXA
YOJMVYUENEO
NXTXAKIQTWN
XGVFOFVLIRT
AJMVFUQAWSI
CFBDNKGDGJL
URNDGWMCEBQ
XHPNQGEMOLA
AKMWRHXUJTC
WTVRILHDRHX
DNJMVKGWZPM
WGCLCZJFIYB
NCSWSAQNWTW
VXHKMJRHRUE
YUJAOYORBEA
HVROXBKTWZD
ORMCAWZVRUE
HDFPLOFIEHR
UDMPMBEHKAP
AXNPRIYBEAX
ITILUDTQTJT
RHYOFUXTJTJ
ZPFCFCUBLPS
LVLHKOPLVLI
JGURGWTISVR
RFDZCSAROQN
ARNXMWTQTJL
SSPYVAHHAKN
EOENRNJEHSH
TQYIRHXHQAW
BRNQFVSIEAX
WGPXTWGWSVK
PMBFUFBKNXG
OKNDGJRUQAQ
MCZILVRPLNC
KRILNDGQGPY
VLNRBFVRBXA
FVXNDTQTDAQ
NQNWMJTDSVS
SISVDZIFNKN
VSOXOXNYMIS
PMDMCFVWZCF
TJFIXAKHQNQ
UDZIFISHRUK
NQSIFVDAQZP
RTWGPSBRHQB
RHJTWYOEHWT |
|
|
|
|