Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误JAVA代码更正它_Java_Class_Enums - Fatal编程技术网

错误JAVA代码更正它

错误JAVA代码更正它,java,class,enums,Java,Class,Enums,//代码意义 //#字符串employee[][]=新字符串[numberOfEmployees][12];将存储/使用详细信息 //#字符串输入将采用字符串格式的员工详细信息 //#字符串选择将选择为“是”以搜索其他员工 /以上代码是关于在招聘管理系统上开发简单JAVA代码的/ import java.util.Scanner; 公共类员工管理{ 公共静态void main(字符串参数[]){ 扫描仪读取=新扫描仪(System.in); System.out.println(“输入员工数量”

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

//#字符串选择将选择为“是”以搜索其他员工 /以上代码是关于在招聘管理系统上开发简单JAVA代码的/
import java.util.Scanner;
公共类员工管理{
公共静态void main(字符串参数[]){
扫描仪读取=新扫描仪(System.in);
System.out.println(“输入员工数量”);
int numberOfEmployees=read.nextInt();//为员工编号提供输入
国际雇员ID;
字符串employee[]]=新字符串[numberOfEmployees][12];

对于(int-inner=0;inner,如果您正确设置问题中的代码格式,将更容易看出哪里出了问题。但首先:

不要像这样比较字符串:

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();







         }



    }
}
choice=="yes"
然后,您只需检查第一个字符串对象是否与第二个字符串对象是同一个对象,在这种情况下,它们永远不会是同一个对象

相反,要这样做:

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();







         }



    }
}
choice=="yes"
或者更好,因为您从未冒过NullPointerException的风险:

choice.equals("yes")

a) 正确设置代码格式b)清楚地问问题这是一个令人愤怒的问题。请避免使用所有大写字母,尤其是当你将其设置为超大粗体时。