public class MainClass
{
public static void main( String args[] )
{
double f = 123.94536;
String s = "Happy Birthday";
System.out.printf( "Using precision for floating-point numbers\n" );
System.out.printf( "\t%.3f\n\t%.3e\n\t%.3g\n\n", f, f, f );
System.out.printf( "Using precision for strings\n" );
System.out.printf( "\t%.11s\n", s );
} // end main
}
Using precision for floating-point numbers
123.945
1.239e+02
124
Using precision for strings
Happy Birth