Strictly speaking, using string input by the user to control the format would look like this:
String format=getFromUser(...);
System.out.printf(format, arg1, arg2, arg3...);
, , , @JohnKugelman, , :
- - ,
WrongFormatConversion :
@Test
public void wrongMask()
{
String s="january";
System.out.printf("%)/$#", s);
}
- , a
MissingFormatArgumentException :
@Test
public void highArgumentIndex()
{
String s="january";
System.out.printf("%1000$s%n", s);
}
@Test
public void highFieldWidth()
{
String s="january";
System.out.printf("%1000000s%n", s);
}
@Test
public void highArgumentWidth()
{
int n=12;
System.out.printf("%01000000d%n", n);
}
. , , , OutOfMemoryError .
( , , , ).
, , .
Update
, , , :
public static void main(String[] args)
{
String format=args[0];
int n=12;
System.out.printf(format, n);
}
, . :
%)/$#%1000$d%1000000d%01000000d
Conclussion: ββ, .