【发布时间】:2015-05-29 04:11:24
【问题描述】:
我可以做到:
int foo = Integer.parseInt("123");
这样int foo = 123
鉴于:
String numbers = "1 2 3"; //note the separation by a space if that helps
int first=
int second=
int third=
是否有一种简单的方法来编写上述内容,以便每个 int 第一、第二和第三个对应于其适当的位置?
【问题讨论】:
-
输入是空格分隔的吗?
-
如果它们被空格分隔,请在结果元素上调用
split()和parseInt。 -
是的,它们被空格分隔,我忘了补充说它们也可以是 2 位数字,并且需要评估每个单独的数字