对我的硬件问题的一部分感到困惑。看起来这很容易,但我不能指望它。我正在尝试以最大和最小销售额返回销售人员。我对如何做到这一点感到困惑。帮助将不胜感激。
import java.util.Scanner;
public class Cray {
public static void main(String[] args){
final int SALESPEOPLE = 5;
int[] sales = new int[SALESPEOPLE];
int sum, maxperson, minperson;
int max = sales[0];
int min = sales[0];
Scanner scan = new Scanner(System.in);
//Fill the 5 element array of sales with the user's input
for (int i=0; i<sales.length; i++)
{
System.out.print("Enter sales for salesperson " + i + ": ");
sales[i] = scan.nextInt();
//Calculate the max and min sales
//How do I return the salesperson i with the the max and min sales?
if(sales[i] > max){
max= sales[i];
}
if(sales[i] < min){
min = sales [i];
}
}
System.out.println("\nSalesperson Sales");
System.out.println("--------------------");
sum = 0;
for (int i=0; i<sales.length; i++)
{
System.out.println(" " + i + " " + sales[i]);
sum += sales[i];
}
System.out.println("\nTotal sales: " + sum);
System.out.println("Average sales: " + sum/5);
//WHere I want to print the max salesperson.
System.out.println("Salesperson" + );
}
}