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;
·
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位数!");
}
}
}
/**
* 任意输入一个整数(小于 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位数!");
}
}
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)