新手有个问题。求个师傅带路答疑!!
package com.imooc; import java.util.Scanner; public class BorrowBook { String[] shu={"高数","大学英语","计算机"}; Scanner sc = new Scanner(System.in); public void test1(){ System.out.println("输入命令1或2:1代表按照书名查找图书;2代表按照序号查找图书"); } public void test2() throws Exception{ test1(); int a1=sc.nextInt(); if (a1!=1||a1!=2){ throw new Exception("命令输入错误;请根据提示输入数字命令!!"); } } public void test3() { try{ test2(); }catch(Exception e){ test3(); } if(a1==1){ System.out.println("请输入图书名"); String a2=sc.next(); for(int i=0;i<3;i++){ if(a2==shu[i]) System.out.println("book:"+a2); } } else if(a1==2) { System.out.println("请输入图书序号"); int b2= sc.nextInt(); for(int i=0;i<3;i++){ if(b2==i) System.out.println("book:"+shu[i]); } System.out.println("图书不存在"); } } }
请大神看一下(main方法放到别处了),错误是:a1 cannot be resolved to a variable。求解释一下哈