Skip to content

Commit c3fb3ab

Browse files
authored
Merge pull request larissalages#215 from sakshii2695/master
Added a java program of Hackerank please move it to java folder
2 parents 07f8e56 + f63aa30 commit c3fb3ab

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
/************************************
3+
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.
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+
Input Format
6+
Every line of input will contain a String followed by an integer.
7+
Each String will have a maximum of alphabetic characters, and each integer will be in the inclusive range from to .
8+
Output Format
9+
In each line of output there should be two columns:
10+
The first column contains the String and is left justified using exactly characters.
11+
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.
12+
Sample Input
13+
java 100
14+
cpp 65
15+
python 50
16+
Sample Output
17+
================================
18+
java 100
19+
cpp 065
20+
python 050
21+
================================
22+
Explanation
23+
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.
24+
***************************************/
25+
import java.util.Scanner;
26+
27+
public class Solution {
28+
29+
public static void main(String[] args) {
30+
Scanner sc=new Scanner(System.in);
31+
System.out.println("================================");
32+
for(int i=0;i<3;i++){
33+
String s1=sc.next();
34+
int x=sc.nextInt();
35+
System.out.printf("%-15s%03d%n", s1, x);
36+
//Complete this line
37+
}
38+
System.out.println("================================");
39+
40+
}
41+
}
42+
43+

0 commit comments

Comments
 (0)