我将用户输入作为“电子邮件电话地址”,并希望返回一个具有相同信息但重新排序“电话地址电子邮件”的数组
import java.util.*;
public class Info {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
String persInfo;
System.out.print("Enter your email phone address: ");
persInfo = userInput.nextLine();
getInfo(persInfo);
}
public static String[] getInfo(String persInfo) {
String[] allInfo = persInfo.split(" ");
String email = allInfo[0];
String phone = allInfo[1];
String address = allInfo[2];
String[] orderedInfo = new String[allInfo.length];
orderedInfo[0] = allInfo[1];
orderedInfo[1] = allInfo[2];
orderedInfo[2] = allInfo[0];
return orderedInfo;
}
}
我认为上面的方法可能有效,但是当我进行测试打印时,我得到了orderedInfo数组的空内容。有任何想法吗?提前致谢。
最佳答案
getInfo(...)
返回一个数组,但您没有存储结果:
final String[] info = getInfo(persInfo);
此外,请将您的分割更改为 ""
,而不是 ""
。
关于java - 返回重新排序的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22592664/