Remove digits from a number in Java [closed]

2019-02-21 18:51发布

How do I remove the first digit of an integer?

My input is an integer (for example i = 123456789).

I then want to remove the first digit, so that i equals 23456789.

7条回答
一夜七次
2楼-- · 2019-02-21 19:45

Alternate approach:

int stripLeading(int i) {
  if(i > 0) {
    return i - (int)Math.pow(10, (int)Math.log10(i));
  } else if(i > 0) {
    return i + (int)Math.pow(10, (int)Math.log(-i+1));
  } else {
    return 0;
  }
}
查看更多
登录 后发表回答