I'm trying to print every element in a character array.
Why am I getting an IllegalFormatConversionException?
public class printf_function_test {
public static void main(String[] args) {
int any = 5;
String object = "car";
char[] ch = {'3','5','6','9'};
System.out.println(ch);
System.out.printf(
"%d anything can happen anytime ,bought a %s and write"
+ "this number now %c",
any,
object,
ch
);
}
}
Stringformat representation of a singlecharvs. achar[]rather than theStringrepresentation of the array (although the question you point at is indeed relevant).%somethingformat is not suitable for asomething[]. The issue about "how do I print a human-readablesomething[]" is secondary to the main issue in my opinion.