我正在使用java并以某种方式具有无限输入,当我想终止循环时,如果输入为空,这是我的代码:我希望有人可以解释我的错误
import java.util.Scanner;
public class Main1{
/*int i=0;*/
private static Customer[] getCustomer(){
Scanner scanner = new Scanner(System.in);
Customer[] customers = new Customer[100];
int i=0;
while((scanner.hasNextLine())){
customers[i++] = new Customer(i,scanner.nextDouble());
}
/*int j;
for(j=1;j<=i;j++){
customers[j] = new Customer(j,sc.nextDouble());*/
return customers;
}
public static void main(String[] args){
int j;
for(j=1;j < getCustomer().length;j++) {
/*Customer[] customer = new Customer(getCustomer());*/
System.out.println(getCustomer());
}
}
}
holdtom
相关分类