我怎样才能看到列表中的Next项

时间:2014-08-04 08:36:16

标签: java

如何查看列表中的下一项?当我使用这段代码时,它总是为空

if (recno!=0){
System.out.print("\n\n\t\t\t\t   Next Record");
System.out.print("\n\n\t\t\t    Employee Number: "+EmpNo[1]);
System.out.print("\n\t\t\t    Employee Number: "+EmpName[1]);
System.out.print("\n\t\t\t    Salary: : "+Salary[1]);
System.out.print("\n\n\t\t  Do you want to see the next record ? [press n]");
next = reader.readLine();

if(next!="y"){
    recno++;

    System.out.print("\n\n\t\t\t    Employee Number: "+EmpNo[recno]);
    System.out.print("\n\t\t\t    Employee Name: "+EmpName[recno]);
    System.out.print("\n\t\t\t    Salary: "+Salary[recno]);
}
}
else{
    System.out.print("\n\n\t\t\t\tRecord Not Found!");
}

1 个答案:

答案 0 :(得分:1)

这肯定有助于在这里使用equals:

if(! "y".equals(next) ){