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.
public static void main(String[] args) {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/
List<Map<String, Integer>> lines = getLines(args);
printLines(lines);
}
public static List<Map<String, Integer>> getLines(String[] args) {
List<Map<String, Integer>> list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String name = scanner.next();
int value = scanner.nextInt();
Map<String, Integer> result = new HashMap<>();
result.put(name, value);
list.add(result);
}
scanner.close();
return list;
}
public static void printLines(List<Map<String, Integer>> list) {
System.out.println("================================");
for (int i = 0;i<list.size();i++) {
Map<String, Integer> map = list.get(i);
map.forEach((k, v) -> { System.out.printf("%-15s%03d\n", k, v); });
}
System.out.println("================================");
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Output Formatting
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}