如何在Java中分隔六位数字

时间:2018-10-14 03:18:26

标签: java

我有一个六位数的数字,所以我想获得前两位数字和后四位数并将其存储在变量中。

int sixDigit = 102020;

我想要这样的东西:

int firstTwo = 10;
int lastFour = 2020;

谢谢!

2 个答案:

答案 0 :(得分:2)

int sixDigit = 102020;
int firstTwo = sixDigit / 10000;
int lastFour = sixDigit % 10000;

答案 1 :(得分:1)

或者您可能想要这个:

int sixDigit = 102020;
String sixDigitString = String.valueOf(sixDigit);
int firstTwo = Integer.valueOf(sixDigitString.substring(0,2));
int lastFour = Integer.valueOf(sixDigitString.substring(2,6));
相关问题