我应该编写一个程序,它接受一个数字并检查它是否可以容纳在某种数据类型中。这是一个片段:
try {
long x=sc.nextLong();
System.out.println(x+" can be fitted in:");
if(x>=-128 && x<=127) {
System.out.println("* byte");
}
else if(x>=-32768 && x<=32768) {
System.out.println("*short");
}
else if(x>= −2147483648l && x<= +2147483647L) {
System.out.println("*int");
}
else if(x>=-9223372036854775808l && x<= +9223372036854775807l) {
System.out.println("*long");
}
} catch(Exception e) {
System.out.println(sc.next()+" can't be fitted anywhere.");
}
当我编译这段代码时,一个奇怪的错误出现了。
Solution.java:30: error: illegal character: \8722
else if(x>= −2147483648l && x<= +2147483647L)
^
Solution.java:30: error: not a statement
else if(x>= −2147483648l && x<= +2147483647L)
^
Solution.java:30: error: ';' expected
else if(x>= −2147483648l && x<= +2147483647L)
^
Solution.java:34: error: 'else' without 'if'
else if(x>=-9223372036854775808l && x<= +9223372036854775807l)
郎朗坤
慕莱坞森
相关分类