这是我的代码:
package com.example.java;
public class PackageDataTest {
public static void main(String[] args) {
PackageData data1 = new PackageData("John Davids");
System.out.printf("%Number of object created until now is : %d", PackageData.count);
}
}
class PackageData {
static int count = 0;
String name;
public PackageData(){
this.name = "";
++count;
}
public PackageData(String name) {
this.name = name;
++count;
}
public int getCount() { return count; }
}
我一直收到以下错误:
“线程中的异常”主“java.util.UnknownFormatConversionException:Conversion ='N'”
答案 0 :(得分:0)
%N不是有效的转换格式,%n是换行符。
所以如果你替换下面的代码:
System.out.printf("%nNumber of object created until now is : %d", PackageData.count);
输出将在新行上:
Number of object created until now is : 1