任意输入一个整数,求该整数有多少位

 1 public class HomeWork032803 {
 2 
 3     /**
 4      * 任意输入一个整数,求该整数有多少位?
 5      */
 6     public static void main(String[] args) {
 7         Scanner s=new Scanner(System.in);
 8         System.out.println("请输入一个整数");
 9         int a=s.nextInt();   //输入的数
10         int c=a;  //保存输入数
11         int i=1;   //统计位数
12         while (a/10>0) {
13             a=a/10;
14             i=i+1;
15         }
16 //        for (;a/10>0; i++) {
17 //            a/=10;
18 //        }
19         System.out.println(c+ "的整数位数:" +i);
20     }
21 
22 }

 

posted on 2016-03-30 20:09  Oliver·Keene  阅读(752)  评论(0)    收藏  举报