ERROR JAVA CODE纠正它

时间:2017-11-18 05:32:13

标签: java class enums

//my code is on java code on employ details using console
//my input is no.of employess
//i am taking input a employ details
//function on searching for a given employ for a given id

//代码含义     // #String employee [] [] = new String [numberOfEmployees] [12];将存储//使用细节 // #String输入将采用字符串格式的员工详细信息。

// #String选择将选择为是以搜索另一名员工

/ 上面的代码是关于在雇佣管理系统上制定简单的JAVA代码 /

import java.util.Scanner;

public class EmployeeManagement {

    public static void main(String args[]){
        Scanner read=new Scanner(System.in);
        System.out.println("Enter  the no.of employees");
        int numberOfEmployees=read.nextInt();//GIVEN INPUT FOR NO.OF EMPLOYESS
        int employeeId;
        String employee[][]=new String[numberOfEmployees][12];
        for(int inner=0;inner<numberOfEmployees;inner++){/*taken input on employ details*/
            for(int outer=0;outer<11;outer++){
                employee[inner][outer]=read.nextLine();
            }
            System.out.println();
        }
        for(int inner=0;inner<numberOfEmployees;inner++){
                 employee[inner][11] = (int)(Integer.parseInt(employee[inner][5])+Integer.parseInt(employee[inner][6])
                                 +Integer.parseInt(employee[inner][7])+Integer.parseInt(employee[inner][8])
                                 -Integer.parseInt(employee[inner][9])-Integer.parseInt(employee[inner][10]));
                           }
        String choice;


                     do{
            System.out.println("do you want to search enter employee id");
            String input=read.nextLine();
            System.out.println("do you want to continue press yes or YES");
                        read.nextLine();
            choice =read.nextLine();        
        }while(choice=="yes" || choice=="YES");
                     for(int inner=0;inner<numberOfEmployees;inner++){
            if(employee[inner][0]=="input"){   
        for(int outer=0;outer<12;outer++)
            System.out.print(employee[inner][outer]);
                                                               }
        System.out.println();







         }



    }
}

1 个答案:

答案 0 :(得分:0)

如果正确格式化问题中的代码,将更容易看出出现了什么问题。但首先要说:

不要比较这样的字符串:

choice=="yes"

然后你只需检查第一个String对象是否与第二个对象是同一个对象,在这种情况下它们永远不会。

相反,请这样:

choice.equals("yes")

或者更好,因为你永远不会冒NullPointerException风险:

"yes".equals(choice)