Skip to content

Commit 4dfad19

Browse files
authored
Merge pull request larissalages#1 from sakshii2695/sakshii2695-patch-1
Create java_output_ formatting.java
2 parents c8a98ac + ef04911 commit 4dfad19

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/************************************
2+
Java's System.out.printf function can be used to print formatted output. The purpose of this exercise is to test your understanding of formatting output using printf.
3+
4+
To get you started, a portion of the solution is provided for you in the editor; you must format and print the input to complete the solution.
5+
6+
Input Format
7+
8+
Every line of input will contain a String followed by an integer.
9+
Each String will have a maximum of alphabetic characters, and each integer will be in the inclusive range from to .
10+
11+
Output Format
12+
13+
In each line of output there should be two columns:
14+
The first column contains the String and is left justified using exactly characters.
15+
The second column contains the integer, expressed in exactly digits; if the original input has less than three digits, you must pad your output's leading digits with zeroes.
16+
17+
Sample Input
18+
19+
java 100
20+
cpp 65
21+
python 50
22+
Sample Output
23+
24+
================================
25+
java 100
26+
cpp 065
27+
python 050
28+
================================
29+
Explanation
30+
31+
Each String is left-justified with trailing whitespace through the first characters. The leading digit of the integer is the character, and each integer that was less than digits now has leading zeroes.
32+
33+
34+
35+
***************************************/
36+
import java.util.Scanner;
37+
38+
public class Solution {
39+
40+
public static void main(String[] args) {
41+
Scanner sc=new Scanner(System.in);
42+
System.out.println("================================");
43+
for(int i=0;i<3;i++){
44+
String s1=sc.next();
45+
int x=sc.nextInt();
46+
System.out.printf("%-15s%03d%n", s1, x);
47+
//Complete this line
48+
}
49+
System.out.println("================================");
50+
51+
}
52+
}
53+
54+
55+

0 commit comments

Comments
 (0)