Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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 查找10个线程的最大值_Java_Arrays_Multithreading_Algorithm_Logic - Fatal编程技术网

Java 查找10个线程的最大值

Java 查找10个线程的最大值,java,arrays,multithreading,algorithm,logic,Java,Arrays,Multithreading,Algorithm,Logic,我有一个程序,它对文本文件进行排序,并使用10个线程提取最大值。然后如何对这10个线程进行排序,并找到这10个线程中的最高值?我的逻辑是将每个结果存储在一个数组中,并将该结果与前一个结果进行比较,但我不确定如何使用线程正确地实现它。我添加了这个for循环,但它不正确。任何帮助都将不胜感激 for (int x = 0; max <=max; x++) { max = worker.getMax(); System.out.p

我有一个程序,它对文本文件进行排序,并使用10个线程提取最大值。然后如何对这10个线程进行排序,并找到这10个线程中的最高值?我的逻辑是将每个结果存储在一个数组中,并将该结果与前一个结果进行比较,但我不确定如何使用线程正确地实现它。我添加了这个for循环,但它不正确。任何帮助都将不胜感激

 for (int x = 0; max <=max; x++) {
                max = worker.getMax();
                System.out.println("Final Max " = max);
            }

for(intx=0;max基本上你的max计算是错误的。下面是更正的代码

int finalMax = workers[0].getMax(); //Sets max as first worker's max

for (int x = 1; x < workers.length; x++) {
     if(finalMax < workers[x].getMax())//checks whether finalMax is less than worker's max at x'th position and if yes assigns it to finalMax         
        finalMax = workers[x].getMax();        
}

System.out.println("Final Max " + finalMax );
int finalMax=workers[0].getMax();//将max设置为第一个worker的max
对于(int x=1;x
什么是不正确的?您得到了什么结果?Hmmm.似乎很接近,但当我尝试执行时,它表示错误:(54,24)java:找不到符号符号:变量工作位置:类数据文件另外,它表示此行需要一个表达式。此外,还将worker[0].getMax()更改为workers[0].getMax()谢谢你的帮助,我将你标记为已接受,并投票支持你!啊,应该停止使用我的电话回答。不用担心!非常感谢!
int finalMax = workers[0].getMax(); //Sets max as first worker's max

for (int x = 1; x < workers.length; x++) {
     if(finalMax < workers[x].getMax())//checks whether finalMax is less than worker's max at x'th position and if yes assigns it to finalMax         
        finalMax = workers[x].getMax();        
}

System.out.println("Final Max " + finalMax );