所以即時工作的任務和我差不多完成了,但我找不到解決方案,適合我。所以我有這些陣列,1要求一個名稱,2要求工作時間和小時率。隨着小時費率和工作時間,我然後創建另一個陣列,給出總薪水。查找數組的最大值,並讓程序給我數組的數量
所以我需要打印出最高的薪水和那個擁有它們的人的名字。
因此,我正在尋找一種方法,可以給我最大值所在的插槽號,所以我可以使用System.out.Println(「a [maxslotnr] +」具有最高的薪水,這是「」d [maxslotnr])
下面是代碼
public class MaxLaun {
public static void main(String args[]) {
StdOut.print("what is the amount of employees ");
int amount = StdIn.readInt();
String[] a = new String[number];
int[] b = new int[number];
int[] c = new int[number];
int[] d = new int[number];
for (int i=0; i < amount; i++) {
StdOut.print("Name of employee");
String name = StdIn.readString();
a[i] = name;
StdOut.print("hourly rate");
int rate = StdIn.readInt();
b[i] = rate;
StdOut.print("amount of worktime");
int time = StdIn.readInt();
c[i] = time;
}
for (int j=0; j < number; j++)
d[j]= (b[j] * c[j]);
}
}
注:你是'number'創建陣列,而不是'amount',它是一個錯字? (在第二個循環中相同)(爲什麼第二個循環?在第一個循環中執行b * c) – AxelH