Note:這些內容都是來自hackerrank的題目筆記和討論區。
先看這道題的解法:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.}題目要求: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. 每行都得要15個characters,數字最多三位,不夠的在前面補充0
這是一種解法: System.out.printf(“%-15s%03d %n”,s1,x);
Explanations: %-15s : left justify 15: Total 15 characters of strig right from begining s: for string %03d 03: Will pad 0 to left if number is less than 3 digit d: for integer %n : for new line
補充的格式輸出: http://www.cnblogs.com/huhx/p/javaFormatter.html#formatter_introduce
新聞熱點
疑難解答