2021年1月3日星期日

How do I split an integer depending on the number of digits of another integer?

I am trying to find a way to split an integer in a specific way. For example,

int A = 69;  int B = 1234569;  

I want to split int B depending on the number of digits of A and place it in an array such as:

//Since number of digits of A is 2  String[] splitB = Integer.toString(B).split(<regex here>);  

splitB should contain: [12, 23, 34, 56, 69]

Another case could be:

int A = 569;  int B = 1234569;    //Since number of digits of A is 3  String[] splitB = Integer.toString(B).split(<regex here>);  

splitB should contain: [123, 234, 456, 569]

https://stackoverflow.com/questions/65556759/how-do-i-split-an-integer-depending-on-the-number-of-digits-of-another-integer January 04, 2021 at 09:46AM

没有评论:

发表评论