public class SimpleTypes{
public static void main(String[] args){
System.out.printf("byte \t数值范围: %d ~ %d\n",Byte.MAX_VALUE, Byte.MIN_VALUE);
System.out.printf("short \t数值范围:%hd ~ %hd\n",Short.MAX_VALUE, Short.MIN_VALUE);
System.out.printf("int \t数值范围: %d ~ %d\n",Integer.MAX_VALUE, Integer.MIN_VALUE);
System.out.printf("long \t数值范围:%ld ~ %ld\n",Long.MAX_VALUE, Long.MIN_VALUE);
System.out.printf("char \t数值范围: %c ~ %c\n",Character.MAX_VALUE, Character.MIN_VALUE);
System.out.printf("float \t数值范围: %f ~ %f\n",Float.MAX_VALUE, Float.MIN_VALUE);
System.out.printf("double \t数值范围:%lf ~ %lf\n",Double.MAX_VALUE, Double.MIN_VALUE);
}
}
为啥char,float,double都不能用呢?我看过这三个都有MAX_VALUE和MIN_VALUE啊。。。求指导。。。
运行结果如下:
byte 数值范围: 127 ~ -128
short 数值范围:7fffd ~ ffff8000d
int 数值范围: 2147483647 ~ -2147483648
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'l'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2606)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2634)
at java.util.Formatter.parse(Formatter.java:2480)
at java.util.Formatter.format(Formatter.java:2414)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at SimpleTypes.main(SimpleTypes.java:7)
------解决方案--------------------