Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Loops 从while loop中查找收入最高的公司_Loops_While Loop_Max_Highest - Fatal编程技术网

Loops 从while loop中查找收入最高的公司

Loops 从while loop中查找收入最高的公司,loops,while-loop,max,highest,Loops,While Loop,Max,Highest,我需要找到收入最高的公司 到目前为止,我能够从循环中获得最高的总收益,但不知道如何获得与最高收益相关的公司名称 而(count您可以将计算后的最高盈利公司名称及其盈利分配到变量中,方法是将之前的最高盈利公司名称与计算后的最高盈利公司名称进行比较 String highCompanyName = "";int highCompanyEarning = 0; while( count <= noOfComp) { System.out.print("Enter Company:

我需要找到收入最高的公司

到目前为止,我能够从循环中获得最高的总收益,但不知道如何获得与最高收益相关的公司名称


而(count您可以将计算后的最高盈利公司名称及其盈利分配到变量中,方法是将之前的最高盈利公司名称与计算后的最高盈利公司名称进行比较

String highCompanyName = "";int highCompanyEarning = 0;
while( count <= noOfComp)
{   
    System.out.print("Enter Company: ");
    companyName = kb.nextLine();

    System.out.print("Number of hires: ");
    noOfHires = kb.nextInt();
    kb.nextLine();


    //calculations
    totalEarnings = noOfHires * 2500 + 10000;
    System.out.println("Total Earnings of company is :" + totalEarnings);
    totalEarned = "" + totalEarnings;


    if(totalEarnings> highCompanyEarning )  //If statement for largest number
    {
        highCompanyEarning = totalEarnings;
        highCompanyName = companyName;
    }


    allTotalEarnings += totalEarnings;//the purpose of it is not clear so left as it is.
    count++;
 }
 System.out.println("Highest Earnings company is :" + highCompanyName );
 System.out.println("Earning of that company is :" + highCompanyEarning );
String highCompanyName=“”;int highCompanyName=0;
while(count highcompanying)//If语句表示最大数
{
高收入=总收入;
highCompanyName=公司名称;
}
allTotalEarnings+=totalEarnings;//它的用途不清楚,只剩下它了。
计数++;
}
System.out.println(“最高收益公司为:“+highCompanyName”);
System.out.println(“该公司的收入为:“+HighCompanyForwarding”);

只是好奇:你是在添加一个带整数的字符串吗?
totalEarned=“”+totalEarnings;
String highCompanyName = "";int highCompanyEarning = 0;
while( count <= noOfComp)
{   
    System.out.print("Enter Company: ");
    companyName = kb.nextLine();

    System.out.print("Number of hires: ");
    noOfHires = kb.nextInt();
    kb.nextLine();


    //calculations
    totalEarnings = noOfHires * 2500 + 10000;
    System.out.println("Total Earnings of company is :" + totalEarnings);
    totalEarned = "" + totalEarnings;


    if(totalEarnings> highCompanyEarning )  //If statement for largest number
    {
        highCompanyEarning = totalEarnings;
        highCompanyName = companyName;
    }


    allTotalEarnings += totalEarnings;//the purpose of it is not clear so left as it is.
    count++;
 }
 System.out.println("Highest Earnings company is :" + highCompanyName );
 System.out.println("Earning of that company is :" + highCompanyEarning );