在java中,如何在一个数组中存储从一个类到另一个类的字符串变量
我该怎么解释。。。在我的java程序中,我必须对一个包含对话框输入的类和另一个包含字符串数组的类进行分类。 在这个程序中,当用户运行它时,我希望用户在对话框输入中输入他们的名字。当他们输入名字时,我希望它存储在另一个类中的字符串数组中,一旦他们的名字存储在变量中,我希望它被打印在控制台中。。我希望这是有道理的谢谢
以下是我迄今为止的工作:
类别1:获取用户名
String name = JOptionPane.showInputDialog("Please Enter Your Name:")
{
// This is where i am a bit stuck as i don't how to send
// the name variable to class 2 and store it in an array
}
类2:从类1获取名称变量
String []names = new String[1];
public String getName()
{
return name; // not working as I am unable to retrieve the name variable
// from class 1
}
String []usernames {name};
System.out.println(usernames); //trying print out the name that is entered.
谢谢你抽出时间
# 1 楼答案
我不明白你想做什么,但这可能是一个答案
但是。。。为什么