• The literal of int xxxxx is out of range


    import java.util.Scanner;

    /**
     * 任意输入一个整数(小于 10 位),求它的位数
     *
     * @author zzu119
     *
     */
    public class digitCount {

        public static void main(String[] args) {
            long absnum = 0;
            long refnum = 999999999;
            while (true) {
                System.out.println("请输入一个小于10位的数字:");
                Scanner input = new Scanner(System.in);
                long num = input.nextLong();
                absnum = Math.abs(num);
                System.out.println("输入数字的绝对值为:" + absnum);
                if (absnum > refnum) {// absnum>9999999999 显示语法错误,The literal of
                                        // type int is out of range
                    /*
                     * Add a capital L to the end: long value =
                     * 9223372036854775807L; Otherwise, the compiler will try to
                     * parse the literal as an int, hence the error message
                     */
                    System.out.println("请输入小于10位的数字!");
                } else {
                    System.out.println("输入为合法数值!");
                    break;
                }
            }
            if (absnum > 99999999) {
                System.out.println("输入数字为9位数!");
            } else if (absnum > 9999999) {
                System.out.println("输入数字为8位数!");
            } else if (absnum > 999999) {
                System.out.println("输入数字为7位数!");
            } else if (absnum > 99999) {
                System.out.println("输入数字为6位数!");
            } else if (absnum > 9999) {
                System.out.println("输入数字为5位数!");
            } else if (absnum > 999) {
                System.out.println("输入数字为4位数!");
            } else if (absnum > 99) {
                System.out.println("输入数字为3位数!");
            } else if (absnum > 9) {
                System.out.println("输入数字为2位数!");
            } else {
                System.out.println("输入数字为1位数!");
            }

        }

    }
  • 相关阅读:
    利用xslt合并多个xml文件到一个文件
    如果利用网络推广老家的特产水果?
    C#并行编程中的Parallel.Invoke
    Asp.Net MVC实现优酷(youku)Web的上传
    修改用户名后TSF出现"需要本地工作区。工作区 xxx 并未驻留在本计算机上"
    JS浏览器滚轮事件实现横向滚动照片展
    Android实现dialog时候弹出软键盘dialog移位问题
    快速搭建多线程Windows服务解决方案
    Difference between WCF and Web API and WCF REST and Web Service
    WPF应用程序的性能提升(一)
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537632.html
Copyright © 2020-2023  润新知