We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Output Formatting
Java Output Formatting
Sort by
recency
|
1446 Discussions
|
Please Login in order to post a comment
It really helps you understand how to control output formatting, which is super useful when displaying clean and readable data—especially in tables or logs. www Raja567 com
For Java 7 and above:
for(int i=0;i<3;i++) { String s1=sc.next(); int x=sc.nextInt(); System.out.printf("%-15s%03d%n", s1, x); }
For Java 11 and above:
for(int i=0;i<3;i++) { String s1=sc.next(); int x=sc.nextInt(); int l=15-s1.length(); System.out.printf("%s%s%03d\n", s1," ".repeat(l), x); }
For Java 7 and above:
For Java15
This is a great exercise for learning how to control output formatting with System.out.printf in Java. Very helpful for beginners! Raja 567
This was a great way to practice formatted output in Java! I liked how the exercise focused on both left-justifying strings and zero-padding integers—super useful skills for beginners to learn early on. Betbricks7 ID