Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 如何在二维数组中获取值 公共级A6{ 公共静态void main(字符串[]args){ //字符串personInfo[][]=新字符串[][]{ 字符串personInfo[][]={ {“安德森”,“瓦莱乔”,“1125”}, {“Giorgi”,“Tevzadze”,“1125”}, {“威尔”,“樱桃”,“1225”}, {“威尔”、“Iams”、“12245”}, {“勒布朗”,“詹姆斯”,“6025”}, {“凯文”,“爱”,“2525”}, {“Kyrie”,“Livings”,“454”}, {“Kyrie”、“Botti”、“4544”}, {“克里斯”,“摩尔”,“425”}, {“Mot”,“Daniel”,“125”}, {“维克多”、“穆勒”、“145”}, {“Kiamran”,“Chris”,“1405”}, {“Zenia”,“Vaitehovic”,“1025”}, {“Marija”,“Grabauskaite”,“1471”}, {“Milda”,“Grabauskaite”,“1000”}, {“迪翁”,“侍者”,“625”}, {“迪翁”、“马尔堡”、“6250”} }; System.out.println(“列表中的人:”); for(int i=0;i_Java_Oop - Fatal编程技术网

Java 如何在二维数组中获取值 公共级A6{ 公共静态void main(字符串[]args){ //字符串personInfo[][]=新字符串[][]{ 字符串personInfo[][]={ {“安德森”,“瓦莱乔”,“1125”}, {“Giorgi”,“Tevzadze”,“1125”}, {“威尔”,“樱桃”,“1225”}, {“威尔”、“Iams”、“12245”}, {“勒布朗”,“詹姆斯”,“6025”}, {“凯文”,“爱”,“2525”}, {“Kyrie”,“Livings”,“454”}, {“Kyrie”、“Botti”、“4544”}, {“克里斯”,“摩尔”,“425”}, {“Mot”,“Daniel”,“125”}, {“维克多”、“穆勒”、“145”}, {“Kiamran”,“Chris”,“1405”}, {“Zenia”,“Vaitehovic”,“1025”}, {“Marija”,“Grabauskaite”,“1471”}, {“Milda”,“Grabauskaite”,“1000”}, {“迪翁”,“侍者”,“625”}, {“迪翁”、“马尔堡”、“6250”} }; System.out.println(“列表中的人:”); for(int i=0;i

Java 如何在二维数组中获取值 公共级A6{ 公共静态void main(字符串[]args){ //字符串personInfo[][]=新字符串[][]{ 字符串personInfo[][]={ {“安德森”,“瓦莱乔”,“1125”}, {“Giorgi”,“Tevzadze”,“1125”}, {“威尔”,“樱桃”,“1225”}, {“威尔”、“Iams”、“12245”}, {“勒布朗”,“詹姆斯”,“6025”}, {“凯文”,“爱”,“2525”}, {“Kyrie”,“Livings”,“454”}, {“Kyrie”、“Botti”、“4544”}, {“克里斯”,“摩尔”,“425”}, {“Mot”,“Daniel”,“125”}, {“维克多”、“穆勒”、“145”}, {“Kiamran”,“Chris”,“1405”}, {“Zenia”,“Vaitehovic”,“1025”}, {“Marija”,“Grabauskaite”,“1471”}, {“Milda”,“Grabauskaite”,“1000”}, {“迪翁”,“侍者”,“625”}, {“迪翁”、“马尔堡”、“6250”} }; System.out.println(“列表中的人:”); for(int i=0;i,java,oop,Java,Oop,我开始做新的自我控制练习。这里我有一个二维字符串数组,它保存着这些信息{“姓名”、“姓氏”、“薪水”}.我已经做了一部分练习,计算有多少人拥有我在命令行中输入的姓名。现在我需要编写一个代码,例如:我进入命令行Anderson Varejao并希望得到结果1125。换句话说,我输入姓名,并希望从personInfo字符串数组中获得某个人的工资。H我怎样才能拿到个人的薪水?for(int I=0;I

我开始做新的自我控制练习。这里我有一个二维字符串数组,它保存着这些信息{“姓名”、“姓氏”、“薪水”}.我已经做了一部分练习,计算有多少人拥有我在命令行中输入的姓名。现在我需要编写一个代码,例如:我进入命令行Anderson Varejao并希望得到结果1125。换句话说,我输入姓名,并希望从personInfo字符串数组中获得某个人的工资。H我怎样才能拿到个人的薪水?

for(int I=0;Ipublic class A6{

    public static void main(String[] args){
        //String personInfo[][]=new String[][] { 
        String personInfo[][]={
                {"Anderson",  "Varejao",     "1125"},
                {"Giorgi",  "Tevzadze",      "1125"},
                {"Will",      "Cherry",      "1225"},
                {"Will",      "Iams",       "12245"},
                {"Lebron",    "James",       "6025"},
                {"Kevin",     "Love",        "2525"},
                {"Kyrie",     "Livings",      "454"},
                {"Kyrie",     "Botti",       "4544"},
                {"Chris",     "Mauer",        "425"},
                {"Mot",       "Daniel",       "125"},
                {"Viktor",    "Muller",       "145"},
                {"Kiamran",   "Chris",       "1405"},
                {"Zenia",     "Vaitehovic",  "1025"},
                {"Marija",    "Grabauskaite","1471"},
                {"Milda",    "Grabauskaite", "1000"},
                {"Dion",      "Waiters",     "625" },
                {"Dion",      "Malborg",    "6250" }
        };


        System.out.println("Peoples on the list:");
        for(int i = 0; i < personInfo.length; i++) {

            for(int j = 0; j < personInfo[i].length; j++) {
                System.out.print(" ");
                System.out.print(personInfo[i][j]);
            }

            System.out.println();
        }
        System.out.println("----------------------");

        //---------v XXX  - how many people have the first name XXX----------------

        String b = "v";

        if(args[0].equals(b))

        {

            System.out.println("Persons with entered name:");

            for(int i = 0; i < personInfo.length; i++) {

                for(int j = 0; j < personInfo[i].length; j++) {

                    if(personInfo[i][j].equals(args[1]))
                    {
                        System.out.println(args[1]);
                    }
                }
            }
            System.out.println();

        }
        //------vp XXX YYY - what is the salary of the person XXX YYY------
    }
}
if(personInfo[i][0].等于(args[1])&& personInfo[i][1]。等于(args[2]){ System.out.println(personInfo[i][2]); } } System.out.println(); 换句话说,我输入一个名字和姓氏,并希望获得的薪水为 personInfo字符串数组中的某个人。我如何够到并取下 一个人的薪水

public class A6{

    public static void main(String[] args){
        //String personInfo[][]=new String[][] { 
        String personInfo[][]={
                {"Anderson",  "Varejao",     "1125"},
                {"Giorgi",  "Tevzadze",      "1125"},
                {"Will",      "Cherry",      "1225"},
                {"Will",      "Iams",       "12245"},
                {"Lebron",    "James",       "6025"},
                {"Kevin",     "Love",        "2525"},
                {"Kyrie",     "Livings",      "454"},
                {"Kyrie",     "Botti",       "4544"},
                {"Chris",     "Mauer",        "425"},
                {"Mot",       "Daniel",       "125"},
                {"Viktor",    "Muller",       "145"},
                {"Kiamran",   "Chris",       "1405"},
                {"Zenia",     "Vaitehovic",  "1025"},
                {"Marija",    "Grabauskaite","1471"},
                {"Milda",    "Grabauskaite", "1000"},
                {"Dion",      "Waiters",     "625" },
                {"Dion",      "Malborg",    "6250" }
        };


        System.out.println("Peoples on the list:");
        for(int i = 0; i < personInfo.length; i++) {

            for(int j = 0; j < personInfo[i].length; j++) {
                System.out.print(" ");
                System.out.print(personInfo[i][j]);
            }

            System.out.println();
        }
        System.out.println("----------------------");

        //---------v XXX  - how many people have the first name XXX----------------

        String b = "v";

        if(args[0].equals(b))

        {

            System.out.println("Persons with entered name:");

            for(int i = 0; i < personInfo.length; i++) {

                for(int j = 0; j < personInfo[i].length; j++) {

                    if(personInfo[i][j].equals(args[1]))
                    {
                        System.out.println(args[1]);
                    }
                }
            }
            System.out.println();

        }
        //------vp XXX YYY - what is the salary of the person XXX YYY------
    }
}
姓名存储在第一个索引中,薪资存储在第二个维度的第三个索引中。
因此,您可以定义一个
findSalary()
方法,该方法依赖于:

for(int i = 0; i < personInfo.length; i++) {
    if(personInfo[i][0].equals(args[1]) &&
            personInfo[i][1].equals(args[2]) {
        System.out.println(personInfo[i][2]);
    }
}
System.out.println();

请注意,使用
String
来表示数字可能不是最好的方法。

按空间分割搜索条件,并将结果存储在数组中,例如:result[2]


选中a[i][j]=result[0]第一部分和&checka[i][j+1]=result[1]第二部分,然后打印期望值,如果您仍然希望使用这种方式,那么这里就是您想要的

String personInfo[][]={ ...};
String salary = findSalary(personInfo, "john");
这是用C写的,希望对你有帮助

class Person {
    String name = "";
    String surName = "";
    String salary = "";
    //setters and getters here
}
string[,]personInfo=新字符串[,]{
{“安德森”,“瓦莱乔”,“1125”},
{“Giorgi”,“Tevzadze”,“1125”},
{“威尔”,“樱桃”,“1225”},
{“威尔”、“Iams”、“12245”},
{“勒布朗”,“詹姆斯”,“6025”},
{“凯文”,“爱”,“2525”},
{“Kyrie”,“Livings”,“454”},
{“Kyrie”、“Botti”、“4544”},
{“克里斯”,“摩尔”,“425”},
{“Mot”,“Daniel”,“125”},
{“维克多”、“穆勒”、“145”},
{“Kiamran”,“Chris”,“1405”},
{“Zenia”,“Vaitehovic”,“1025”},
{“Marija”,“Grabauskaite”,“1471”},
{“Milda”,“Grabauskaite”,“1000”},
{“迪翁”,“侍者”,“625”},
{“迪翁”、“马尔堡”、“6250”}
};
string FirstName=“Milda”;
字符串LastName=“Grabauskaite”;
for(int i=0;i
关于如何在数组中定位元素,由于薪资始终在personInfo[2]中,我将一次迭代数组一行,检查firstName是否对应于peopleinfo[0]中的元素&lName对应于peopleinfo[1]。 看起来像这样:

string[,] personInfo = new string[,] { 
    {"Anderson",  "Varejao",     "1125"},
    {"Giorgi",  "Tevzadze",      "1125"},
    {"Will",      "Cherry",      "1225"},
    {"Will",      "Iams",       "12245"},
    {"Lebron",    "James",       "6025"},
    {"Kevin",     "Love",        "2525"},
    {"Kyrie",     "Livings",      "454"},
    {"Kyrie",     "Botti",       "4544"},
    {"Chris",     "Mauer",        "425"},
    {"Mot",       "Daniel",       "125"},
    {"Viktor",    "Muller",       "145"},
    {"Kiamran",   "Chris",       "1405"},
    {"Zenia",     "Vaitehovic",  "1025"},
    {"Marija",    "Grabauskaite","1471"},
    {"Milda",    "Grabauskaite", "1000"},
    {"Dion",      "Waiters",     "625" },
    {"Dion",      "Malborg",    "6250" } 
};

string FirstName = "Milda";
string LastName = "Grabauskaite";

for (int i = 0; i < personInfo.GetLength(0); i++)
{
    if(personInfo[i,0] == FirstName && personInfo[i,1] == LastName)
    {
        Console.WriteLine(FirstName + " " + LastName + " Salary Is: " + personInfo[i,2]);
    }
}

请重新格式化你的代码,这真的一点也不可读。但是对于你的问题:只需搜索一个名字合适的人并打印出薪水就可以了,或者?因此,从“搜索一个人”复制你的代码,只需打印出他们的薪水而不打印出此人。循环数组的外部维度,然后。。。。
string[,] personInfo = new string[,] { 
    {"Anderson",  "Varejao",     "1125"},
    {"Giorgi",  "Tevzadze",      "1125"},
    {"Will",      "Cherry",      "1225"},
    {"Will",      "Iams",       "12245"},
    {"Lebron",    "James",       "6025"},
    {"Kevin",     "Love",        "2525"},
    {"Kyrie",     "Livings",      "454"},
    {"Kyrie",     "Botti",       "4544"},
    {"Chris",     "Mauer",        "425"},
    {"Mot",       "Daniel",       "125"},
    {"Viktor",    "Muller",       "145"},
    {"Kiamran",   "Chris",       "1405"},
    {"Zenia",     "Vaitehovic",  "1025"},
    {"Marija",    "Grabauskaite","1471"},
    {"Milda",    "Grabauskaite", "1000"},
    {"Dion",      "Waiters",     "625" },
    {"Dion",      "Malborg",    "6250" } 
};

string FirstName = "Milda";
string LastName = "Grabauskaite";

for (int i = 0; i < personInfo.GetLength(0); i++)
{
    if(personInfo[i,0] == FirstName && personInfo[i,1] == LastName)
    {
        Console.WriteLine(FirstName + " " + LastName + " Salary Is: " + personInfo[i,2]);
    }
}
static Scanner sc = new Scanner(System.in);

static String personInfo[][] = {
    {"Anderson", "Varejao", "1125"},
    {"Giorgi", "Tevzadze", "1125"},
    {"Will", "Cherry", "1225"},
    {"Will", "Iams", "12245"},
    {"Lebron", "James", "6025"},
    {"Kevin", "Love", "2525"},
    {"Kyrie", "Livings", "454"},
    {"Kyrie", "Botti", "4544"},
    {"Chris", "Mauer", "425"},
    {"Mot", "Daniel", "125"},
    {"Viktor", "Muller", "145"},
    {"Kiamran", "Chris", "1405"},
    {"Zenia", "Vaitehovic", "1025"},
    {"Marija", "Grabauskaite", "1471"},
    {"Milda", "Grabauskaite", "1000"},
    {"Dion", "Waiters", "625"},
    {"Dion", "Malborg", "6250"}
};

public static void main(String[] args) {

    System.out.print("Enter First Name: ");
    String fName = sc.nextLine();
    System.out.print("Enter Last Name: ");
    String lName = sc.nextLine();
    System.out.println(fName + " " + lName + "' Salary: " + salaryLookUp(personInfo, fName, lName));

}

static String salaryLookUp(String[][] array, String fName, String lName) {
    String salary = "";

    for (String[] row : personInfo) {
        if (row[0].equalsIgnoreCase(fName) && row[1].equalsIgnoreCase(lName)) {
            salary = row[2];
            break;
        } else {
            salary = "Not Found";
        }
    }
    return salary;
}