How do I make a progression with a variable in Java?

谁说我不能喝 提交于 2019-12-31 05:54:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!