You are viewing a single comment's thread. Return to all comments →
import java.util.Scanner;
public class Solution {
public static void main(String[] args) { Object[][] dataset = new Object[3][2]; Scanner sc = new Scanner(System.in); System.out.println("================================"); for(int i = 0; i<3; i++){ String s = sc.next(); int n = sc.nextInt(); Object[] pair = {s, n}; dataset[i] = pair; } sc.close(); for(int j = 0; j < 3; j++) { System.out.println(modifyString((String)dataset[j][0]) + modifyNum((int)dataset[j][1])); } System.out.println("================================"); } private static String modifyString(String str) { String newStr = str; for(int i = 0; i < (15 - str.length()); i++) { newStr += " "; } return newStr; } private static String modifyNum(Integer val) { int numOfNum = (int)Math.log10((double)val); switch(numOfNum) { case 0: return "00" + val.toString(); case 1: return "0" + val.toString(); case 2: return val.toString(); default: return "000"; } }
}
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.util.Scanner;
public class Solution {
}