Java – retrieves the first number of a number

See the English answer > return first digit of an integer18

int number = 534;
String numberString = Integer.toString(number);
char firstLetterChar = numberString.charAt(0);
int firstDigit = ????

Solution

int number = 534;
int number = 534;
    int firstDigit = Integer.parseInt(Integer.toString(number).substring(0,1));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>