java中求一个long数字的位数(在线等)

求long整数的位数( 能求负数位数,包括0也能求出位数,要用Scanner输入)

只能用+ - * / 还有下面的语法。。
http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#addExact-int-int-
而且只能用一条公式表达出==
请各位大神帮忙!
补充一下。只能用提供网站的method来编程、、谢谢各位大神
只能用+ - * /, and the methods in the Math class in the website.
It must be a one-line formula using only the allowable operations above。(老师原话,不太会翻译专业术语不好意思)

语法?一条公式?搞不清你说的是什么意思。

没仔细看你的要求,重新修改了一下。

        Scanner input = new Scanner(System.in);
        System.out.println("请输入数字!");
        String str = input.next();
        Long data = 0L;
        try {
            data = Long.valueOf(str);
        } catch (NumberFormatException e) {
            System.out.println("你输入的不是数字");
            return;
        }
        int size = 1;
        while ((data = data / 10) != 0) {
            size++;
        }
        input.close();
        System.out.println("数字的位数:" + size);

 请说的专业一点吧。越看越坑,“只能用提供网站的class来编程”实在是听不懂。

追问

只能用+ - * /, and the methods in the Math class in the website.
It must be a one-line formula using only the allowable operations above。
我翻译得不好。以上英文是老师原话,我不会翻译成中文。
应该是只能网站里面的method,不好意思。我是刚刚学java的

追答      这样应该没问题了吧。好像没必要使用其他的方法。
        Scanner input = new Scanner(System.in);
        System.out.println("请输入数字!");
        Long data = 0L;
        try {
            data = input.nextLong();
        } catch (Exception e) {
            System.out.println("你输入的不是数字");
            return;
        }
        int size = 1;
        while ((data = data / 10) != 0) {
            size++;
        }
        input.close();
        System.out.println("数字的位数:" + size);

追问

能不能用到网页的method。。这里try,catch 和while我还没学过~

追答

没事,不会就去掉,那个只是防止页面输入不是非数字的时候做的一个提醒。你直接去掉try cath这一段,这么写就行:Long data = input.nextLong();

温馨提示:答案为网友推荐,仅供参考