
October 1st, 2002, 01:15 AM
|
|
Moderator =(8^(|)
|
|
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710
Time spent in forums: 20 m 38 sec
Reputation Power: 8
|
|
You keep finding these interesting problems
PHP Code:
String input = "20020925-2-6";
java.util.StringTokenizer tok = new java.util.StringTokenizer( input, "-" );
if ( tok.countTokens() == 3 ) {
String[] parts = new String[3];
int ndx = 0;
while( tok.hasMoreTokens() ) {
parts[ndx] = tok.nextToken();
ndx++;
}
java.text.DecimalFormat df1 = new java.text.DecimalFormat( "00000000" );
java.text.DecimalFormat df2 = new java.text.DecimalFormat( "000" );
java.text.DecimalFormat df3 = new java.text.DecimalFormat( "00" );
String output = df1.format( Double.parseDouble( parts[0] ) ) + "-" + df2.format( Double.parseDouble( parts[1] ) ) + "-" + df3.format( Double.parseDouble( parts[2] ) );
out.print( output );
} else {
out.print( "Shame on you. The input is the wrong format." );
}
Last edited by bricker42 : October 1st, 2002 at 01:18 AM.
|