如何使用Java中的变量进行演化? [英] How do I make a progression with a variable in Java?

查看:99
本文介绍了如何使用Java中的变量进行演化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何调用更改的变量感兴趣,例如 customer1 customer2 customer3 等。这些客户变量填充在此特定中。我希望程序在我执行诸如 customer1.returnName(); 之类的操作时自动输入该数字,如果用户键入 1 。没有我根据案例代码做出案例。我希望用户输入客户编号,然后自动使用该编号。什么功能最适合这个?

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?

推荐答案

如果您有编号变量,请使用列表。类似

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();

这篇关于如何使用Java中的变量进行演化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆