zoukankan      html  css  js  c++  java
  • 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位数!");
            }

        }

    }
  • 相关阅读:
    Putty·Network error:Software caused connection abort
    VSCode·搭建Java开发环境
    MSSQL·将一对多的数据合并为以指定分隔符的数据
    技能Get·Windows10将任何格式文件固定到开始屏幕
    MSSQL·查询TSQL语句执行时间的三种方法
    Javac·编码GBK的不可映射字符
    傅里叶变换、拉氏变换、z变换的含义
    宏、内联函数和普通函数的区别
    OpenGL中创建GLUT菜单
    在PC安裝Android系統+軟體
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537632.html
Copyright © 2011-2022 走看看