슈퍼마켓은 슈퍼마켓의 화면에 고객의 이름을 표시하여 매일 최고의 고객에게 보상을 제공하려고합니다. 이를 위해 고객의 구매 금액은 ArrayList에 저장되고 고객의 이름은 해당 ArrayList에 저장됩니다. 가장 큰 판매를 가진 고객의 이름을 반환하는 public static String nameOfBestCustomer (ArrayList sales, ArrayList customers) 메서드를 구현합니다. 계산원에게 모든 가격과 이름을 입력하고, 두 개의 배열 목록에 추가하고, 구현 한 방법을 호출하고 결과를 표시하도록하는 프로그램을 작성하십시오. 가격 0을 센티넬으로 사용하십시오.for 루프를 사용하여 ArrayList에 숫자 추가 - Java
지금까지 for 루프를 사용하여 키보드로 숫자/이름을 배열에 입력하는 데 문제가 있습니다. 이것은 내가 지금까지 가지고있는 것이다.
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
public class TopCustomer {
public static String nameOfBestCustomer(ArrayList<Double> sales, ArrayList<String> customers) {
}
public static void main (String [] args){
ArrayList<Double> sales = new ArrayList<Double>();
ArrayList<String> customer = new ArrayList<String>();
Scanner in = new Scanner(System.in);
System.out.print("How many Customers are there?");
int num = in.nextInt();
for (int i = 1; num <= i; i++) {
System.out.print("Enter name of customer " + i + ": \n");
customer.add(i) = in.nextString();
System.out.print("Enter how much customer " + i + ": \n");
sales.add(i) = in.nextDouble();
}
}
}
'customer.add (in.nextString());'을 사용하십시오. – Braj
계속 오류가 발생합니다. 기호를 찾을 수 없습니다. customer.add (in.nextString()); – Sjanes227