Rogerl
2015-06-29 12:34
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。求解释一下哈
a1在test2里面定义过,是局部变量,在test3方法中没有定义使用不了
这代码输出不了啊
楼上对的
= = 楼上对的。
Java入门第三季
409776 学习 · 4546 问题
相似问题