You are viewing a single comment's thread. Return to all comments →
import java.util.Scanner; import java.util.LinkedHashMap; import java.util.Map; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<String, String> myHashMap = new LinkedHashMap<>(); for (int i = 1; i <=3; i++){ String s = sc.next(); int n = sc.nextInt(); String num = ""; if (n < 10){ num = "00" + String.valueOf(n); }else if (n<100 && n>=10){ num = "0" + String.valueOf(n); }else{ num = String.valueOf(n); } myHashMap.put(s, num); } System.out.println("================================"); for (Map.Entry<String, String> entry : myHashMap.entrySet()){ System.out.printf("%-14s %s \n", entry.getKey(), entry.getValue()); } System.out.println("================================"); } }
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 →