Java 如何将数组空间设为给定的数字x
当(x!=0){x=x/10时,如何使数组x的数字空间不做上限; ++数字;}Java 如何将数组空间设为给定的数字x,java,Java,当(x!=0){x=x/10时,如何使数组x的数字空间不做上限; ++数字;} public static void main() { int x = 12345; int digit=0; while(x!=0) { x=x/10; ++digit; } // how to make array x's digit space not doing upper while(x!=0) {...} int[] arra
public static void main() {
int x = 12345;
int digit=0;
while(x!=0) {
x=x/10;
++digit;
}
// how to make array x's digit space not doing upper while(x!=0) {...}
int[] array = new int[digit];
}
为了获得整数的位数,一种方法是将整数转换为字符串,并检查结果字符串的长度:
int digit = 123456; //your int
int length = ("" + digit).length(); //i.e. the length of "123456"
你应该更准确地解释这个问题。