判断一个数(不仅是小于10位,还包括大于10位)的位数,例如输入999999999999,则输出“它是个12位的数”
package imooc.com;
import java.util.Scanner;
public class Demo3 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("***请输入一个判断位的数***");
long num=input.nextLong();
long i=10;
long count=1;
while((num/i)!=0)
{
i*=10;
count++;
}
System.out.println("输入实数位数为:"+count);
}
}
public class HelloWorld{
public static void main(String[] args){
long num = 999999999999l;
int count = 0;
if(num>=0 ){
do{
count++;
num=num/10;
}
while (num>0);
System.out.println("它是个"+count+"位的数!");
}
else
System.out.println("输入数据错误");
}
}
public class HelloWorld{
public static void main(String[] args){
long num = 999999999999l;
int count = 0;
do{
count++;
num=num/10;
}while(num>0);
System.out.println("它是个"+count+"位的数!");
}
}
public class HelloWorld{ public static void main(String[] args){ long int num = 999999999999; int count = 0; if(num>=0 ){ do{ count++; num=num/10; } while (num>0); System.out.println("它是个"+count+"位的数!"); } else System.out.println("输入数据错误"); } }