输入一个不超过10的九次方的正整数,输出它的位数。例如12735的位数是5,请不要使用任何的数学函数,只用四则运算和循环语句实现。
样例输入:12345
样例输出:5
下面贴出源码:
package cn.zimo.algorithm;import java.util.Scanner;/*** 位数 digit* @author 子墨* @date 2018年4月26日 下午1:29:43*/
public class Demo07 {public static void main(String[] args) {int n=new Scanner(System.in).nextInt(),count=0;while(n>0) {n=n/10;count++;}System.out.println(count);}}