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
|
1453 Discussions
|
Please Login in order to post a comment
As far as I know Java 7 does not receive free public updates anymore. That means the version's relevance is minimal, if not null. Hackerrank should definitely check on this.
import java.util.Scanner;
public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in);
}
java 15
System.out.printf("%-15s%03d\n",s1,x); Here "%-15s", "%03d" everyone's doubt why we are using -15, 03 because in that question had clearly mentioned the excepted output "java" and "100" occupy 15 character spaces. '-' left-align the string in the 15-character field. %s reads the string the s1, and "%03d" %d is used as to read the integer values and occupy 3 digits.0 pad with leading zeros if the number is less than 3 digits. example : 65 is convert into 065
Great exercise for getting comfortable with formatted output in Java! fairplay 24 pro