Input Format
Every line of input will contain a String followed by an integer. Each String will have a maximum of 10 alphabetic characters, and each integer will be in the inclusive range from 0 to 999.
Output Format
In each line of output there should be two columns: The first column contains the String and is left justified using exactly 15 characters.
The second column contains the integer, expressed in exactly 3 digits; if the original input has less than three digits, you must pad your output's leading digits with zeroes.Sample Input
java 100 cpp 65 python 50
Sample Output
================================ java 100 cpp 065 python 050 ================================
printf
is pretty straightforward. Two formats per row, newline at the end. The lines that don't need to be formatted (first and last) can be put on the screen using println
instead. To the best of my knowledge it isn't possible to put both printf
statements in one printing statement, so I made it a function instead. Keeps things neat.
My naming is probably horrible. As usual.
import java.util.Scanner;
public class Solution {
private static void printRowOutlined(String left, int right) {
System.out.printf("%-15s", left);
System.out.printf("%03d\n", right);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("================================");
for(int i = 0; i < 3; i++){
String text = sc.next();
int number = sc.nextInt();
printRowOutlined(text, number);
}
System.out.println("================================");
}
}