【发布时间】:2022-01-19 23:11:43
【问题描述】:
我需要一种方法来从字符串中获取特定的“随机”数字,并将它们分别放入单独的 int 变量中。
例如,这个字符串不能/不应该改变:
String date = "59598 22-01-19 22:46:32 00 0 0 66.2 UTC(NIST) * ";
我需要将这三个数字放在单独的整数“22-01-19”中。 因此,一个 int 称为“day”,它保存数字 19,另一个 int 称为“month”,它保存数字 1,另一个 int 称为“year”,它保存数字 22。
这就是它的样子:
String date = "59598 22-01-19 22:46:32 00 0 0 66.2 UTC(NIST) * ";
int day = 0;
int month = 0;
int year = 0;
//(method for finding these numbers and putting them into the separate int variables)
System.out.println(year+" "+month+" "+day);
提前谢谢你!
注意:我没有找到一个解释得足够好让我理解的解决方案,如果这个问题已经存在重复,我深表歉意。
【问题讨论】: