我正在制作一个程序,它接受用户输入的 3 个数字,然后将这些单独的数字与我拥有的数字进行比较。
如何将这些使用输入数字拆分并保存为单独的整数?
最佳答案
String.split()和 Integer.parseInt()是你的 friend 。
String input = "1 2 3";
String[] spl = input.split(" "); //Or another regex depending on the input format
for (String s : spl) {
System.out.println(Integer.parseInt(s)); // or store them as you like
}
关于java - 分割输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655239/