我试图用d
声明为double
和 not创建这个程序Double
,你能告诉我为什么这个程序不运行吗?它不应该被自动包装和解包,比如原始数据类型的装箱和拆箱吗?PS - 我是 Java 新手,我不记得它实际上是什么,但我在某处读到这被称为原始类型的装箱和拆箱以在它们上运行方法。
public class ToStringDemo {
public static void main(String[] args) {
double d = 858.48;
String s = d.toString();
int dot = s.indexOf('.');
System.out.println(dot + " digits " +
"before decimal point.");
System.out.println( (s.length() - dot - 1) +
" digits after decimal point.");
}
}
注意 - 上面的程序给出了错误String s = d.toString();