我正在使用 Java 制作一个程序,它将输出用户的星座。当我编译此代码时,它会突出显示 0219 并显示“整数太大”。我是初学者,所以如果这是一个愚蠢的错误,请多多包涵。谢谢
System.out.println("Please enter your birthday month and day as a four digit number");
System.out.println("(Ex: 0514 for May 14th):");
double d = key.nextDouble();
if (d >= 0101 && d <= 0120) {
System.out.println("You are a Capricorn.");
}
else if (d >= 0121 && d <= **0219**) {
System.out.println("You are an Aquarius.");
}
else if (d >= 0220 && d <= 0320) {
System.out.println("You are a Pisces.");
}
else if (d >= 0321 && d <= 0420) {
System.out.println("You are an Aries.");
}
else if (d >= 0421 && d <= 0521) {
System.out.println("You are a Taurus.");
}
else if (d >= 0522 && d <= 0621 ) {
System.out.println("You are a Gemini.");
}
else if (d >= 0622 && d <= 0723 ) {
System.out.println("You are a Cancer.");
}
最佳答案
数字以 0 开头意味着它被解释为八进制,这使得“9”成为无效数字。
关于java - 太大的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27179678/