Need help with printf with java 1.5
Here is a tiny section of the java code I am writing
// Pad Method
public static void pad( int pnum, int pwidth) throws IllegalArgumentException
{
if (pnum <= 0 || pwidth <=0 )
throw new IllegalArgumentException( "Plese enter a positive number and try again!" );
// create string of pnum to add to printf below
String s = String.valueOf( pnum );
System.out.printf( "\t%.(Integer.intValue(pwidth)\n", s);
}
It doesn't work and the java runtime vomits with a class conversion error. I need to learn more about printf introduced in Java5.
The internet and javadocs are written in greek and I see nothing about using \t% for padding in the javadocs but examples on the web use it.
I did write a successfull test app that Worked with the padding!
String s = "Happy Birthday!";
System.out.printf("\t%.11s\n", s)
// Pad Method
public static void pad( int pnum, int pwidth) throws IllegalArgumentException
{
if (pnum <= 0 || pwidth <=0 )
throw new IllegalArgumentException( "Plese enter a positive number and try again!" );
// create string of pnum to add to printf below
String s = String.valueOf( pnum );
System.out.printf( "\t%.(Integer.intValue(pwidth)\n", s);
}
It doesn't work and the java runtime vomits with a class conversion error. I need to learn more about printf introduced in Java5.
The internet and javadocs are written in greek and I see nothing about using \t% for padding in the javadocs but examples on the web use it.
I did write a successfull test app that Worked with the padding!
String s = "Happy Birthday!";
System.out.printf("\t%.11s\n", s)
Prints Happy Birthda and sucessfully cuts it to 11 characters which are required for method pad.
I just want the umber for pwidth (for pad width) to use for the tab object.
So what am I doing wrong and how do I take the value of pwidth to pad the value of pnum?
