问题
I am interested in how to call a variable that changes, such as customer1
, customer2
, customer3
, etc. These customer variables are populated in this particular Class
. I would like the program to automatically type that number when I perform something such as customer1.returnName();
if the user types a 1
. without me making a case by case code. I would like the user to type the number of the customer and it automatically uses that number. What function is best for this?
回答1:
If you have numbered variables, then use a list. Something like
ArrayList<Customer> customers = new ArrayList<Customer>();
customers.add(new Customer("name"));
customers.get(0).returnName();
来源:https://stackoverflow.com/questions/36345825/how-do-i-make-a-progression-with-a-variable-in-java