有些大神用减法来求位数,怎么想出来的呢
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 1;
int data,i,j;
for(i=1;i<=10;i++)
{
count=count*10;
data=num-count;
if(data<0)
{break;}
}
System.out.println("它是个"+i+"位的数!");
}
}
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 1;
int data,i,j;
for(i=1;i<=10;i++)
{
count=count*10;
data=num-count;
if(data<0)
{break;}
}
System.out.println("它是个"+i+"位的数!");
}
}
2019-03-03
举报