Java 从数组中标识项目?

Java 从数组中标识项目?,java,arrays,Java,Arrays,我有3个阵列,并行工作。我需要让用户能够从数组中识别一个项目,删除它及其信息,或者编辑它的信息 这就是我到目前为止所做的: private static int identifyComputer(String[] computerBrand, double[] computerSpeed, double[] computerPrice) { Scanner keyboard = new Scanner(System.in); int counter = computerBrand

我有3个阵列,并行工作。我需要让用户能够从数组中识别一个项目,删除它及其信息,或者编辑它的信息

这就是我到目前为止所做的:

private static int identifyComputer(String[] computerBrand, double[] computerSpeed, double[] computerPrice) {
    Scanner keyboard = new Scanner(System.in);
    int counter = computerBrand.length;
    System.out.println("Computer brand?");
    String cb = keyboard.nextLine();
    int i = 0;
    boolean notFound = true;
    for (i = 0; i < counter && notFound; i++)
    {
        if (cb.equals(computerBrand[i])) 
        {
            System.out.println(computerBrand[i]);
            System.out.println(computerSpeed[i]);
            System.out.println(computerPrice[i]);
            notFound = false;
     }


    if (notFound) {
        return -1;
    } 

    else  
    {
        System.out.println("Computer Speed?");
        String cs = keyboard.nextLine();

        boolean notFound2 = true;
        for (i = 0; i < counter && notFound2; i++)
        {
            if (cs.equals(computerSpeed[i])) 
         {
                System.out.println(computerBrand[i]);
                System.out.println(computerSpeed[i]);
                System.out.println(computerPrice[i]);
                notFound2 = false;
            }
        }
        if (notFound) {
            return -1;

        } else {
            System.out.println("Computer Price?");
            String cp = keyboard.nextLine();

            boolean notFound3 = true;
            for (i = 0; i < counter && notFound3; i++)
            {
                if (cp.equals(computerPrice[i])) 
            {
                    System.out.println(computerBrand[i]);
                    System.out.println(computerSpeed[i]);
                    System.out.println(computerPrice[i]);
                    notFound3 = false;
                }
            }

            if (notFound) {
                return -1;
        }
      }
    }
  }       
    return i;
}
private static int identificationcomputer(字符串[]computerBrand,双[]computerSpeed,双[]computerPrice){
扫描仪键盘=新扫描仪(System.in);
int计数器=computerBrand.length;
System.out.println(“计算机品牌?”);
字符串cb=keyboard.nextLine();
int i=0;
布尔notFound=true;
对于(i=0;i
但我知道你不是100%这样做的。它在for循环上有一些错误,不能正常工作。我试图让用户能够识别计算机并返回该计算机的索引。但我也不确定这一点。
(我不能使用ArrayList)

将信息并行存储在三个数组中会让人困惑。我强烈建议您使用所有信息创建一个新类型的对象,并创建该对象的单个数组:

class Computer {
    String brand;
    int speed;
    double price;
}

接下来,创建一个
Computer
对象数组,并通过该数组操作类
Computer
中的变量。您的代码将更容易编写。

有什么问题吗?另外,不要在随机网站上发布代码,请在此处发布相关部分。我如何在此处发布整个代码?@user3261569相关部分点击查看,谢谢。我想我会遇到字符left count max。在搜索计算机品牌时找到某个东西后,您似乎正在将
notFound
设置为
true
。那是故意的吗?如果可以的话我会的。。但是我们并没有真正学到很多课程,也没有说我们应该使用它们。这是更好的编码实践。教授要求我们不要…:/