Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (10.2k points)

Printf got added to Java with the 1.5 release but I can't seem to find how to send the output to a string rather than a file (which is what sprintf does in C). Does anyone know how to do this?

1 Answer

0 votes
by (46k points)
edited by

// Store the formatted string in 'result'

String result = String.format("%4d", i * j);

// Write the result to standard output

System.out.println( result );

Want to learn Spring from the scratch? Here's is the right video for you on Spring provided by Intellipaat

Check out the format and some of the syntax

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 24, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 26, 2019 in Java by Nigam (4k points)

Browse Categories

...