第一章最后一节课,模拟图书系统的作业,这是我敲的代码,程序没有报错,为什么没有结果呢?求大神指教
package exception.test;
import java.util.Scanner;
public class LibrarySystem {
public static void main(String[] args){
LibrarySystem ct=new LibrarySystem();
try{
ct.test();
}catch(Exception e){
e.printStackTrace();
}
try{
ct.test1();
}catch(Exception e){
e.printStackTrace();
}
}
public void test(){
@SuppressWarnings("resource")
Scanner console = new Scanner(System.in);
int num=console.nextInt();
try{
if(num==1)
System.out.println("1-按照名称来查找图书");
else if(num==2) System.out.println("2-按照序号来查找图书");
}catch(Exception e){
e.printStackTrace();//打印出异常的具体情况
System.out.println("错误命令异常,请重新输入");
}
}
public void test1(){
String [] books={"语文","高数","C语言","英语","化学","计算机"};
@SuppressWarnings("resource")
Scanner console = new Scanner(System.in);
int num=console.nextInt();
try{
if(num==1){
System.out.println("请输入序号来查找图书");
int num1=console.nextInt();
for(int i=0;i<books.length;i++){
if(num1==i){
System.out.println(books[i]);
}
else if(num==2){
System.out.println("请按照名称来查找图书");
String name = console.next();
for(int j=0;j<books.length;j++){
if(name.equals(books[j]))
System.out.println(books[j]);
}
}
}
}
}catch(Exception e){
e.printStackTrace();//打印出异常的具体情况
System.out.println("图书不存在异常,请重新输入");
}
}
}