package project3;
import java.util.InputMismatchException;
import java.util.Scanner;
public class JieShu {
static Scanner sn = new Scanner(System.in);
static int a = 0 ;
static String[] shu = {"语文","高数","英语","java","政治","历史","地理"};
public static void main(String[] args) {
do{
shuru();
if(a == 1){
name();
}else if(a == 2){
number();
}
else
System.out.println("命令输入错误,请根据提示输入");
}while(true) ;
}
public static void shuru(){
System.out.println("输入命令:1-按照书名寻找图书,2-按照序号寻找图书");
try{
Scanner sc = new Scanner(System.in) ;
a = sc.nextInt() ;
}catch(InputMismatchException e){
//System.out.println("命令输入错误,请根据提示输入命令");
}
}
public static void name(){
System.out.println("请输入图书名称");
String n = sn .next();
for(int i=0;i<shu.length;i++){
if(n.equals(shu[i]))
System.out.println("book:"+shu[i]);
else if(i == shu.length-1)
System.out.println("图书不存在");
}
}
public static void number(){
System.out.println("请输入图书序号");
int b = 0 ;
boolean k ;
do{
try{
Scanner scn = new Scanner(System.in) ;
b = scn.nextInt() ;
k = false ;
if(b<=shu.length)
System.out.println("book:"+shu[b-1]);
else
System.out.println("图书不存在");
}catch(InputMismatchException e){
System.out.println("命令输入错误,请输入图书序号");
k = true ;
}
}while(k) ;
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章