This is my code:
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; }
}
I keep receiving the following error:
"Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'N'"
%N is not a valid conversion Format and %n is for the line break.
so if you replace the code as below:
System.out.printf("%nNumber of object created until now is : %d", PackageData.count);
output will be on new line:
Number of object created until now is : 1
check this discussion: What's up with Java's "%n" in printf?