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位数!");
            }

        }

    }
  • 相关阅读:
    HTML5和HTML4之间的区别
    HttpRequest信息内容介绍
    Spring Web MVC处理请求的流程
    游戏中的路径动画设计与实现
    Python基本数据类型
    Python基本数据类型
    perl .= 操作符
    出差二、三事——北漂18年(25)
    perl 卸载Oracle数据库
    perl 卸载mysql数据库
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537632.html
Copyright © 2011-2022 走看看