0

私は最高の収益を上げている会社を見つける必要があります。

これまでのところ、ループから最高の総収益を引き出すことができますが、この最高の収益に結びつく会社名を取得する方法がわかりません。

while( カウント <= 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 > large )                          //If statement for largest number
    {
     large = totalEarnings;
    }


    allTotalEarnings += totalEarnings;
    count++;


}
4

1 に答える 1

0

前回の最高値と計算されたものを比較することにより、計算後に最高収益の会社名とその収益を変数に割り当てることができます。

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 );
于 2014-12-15T14:25:06.787 に答える