[HackerRank](4)Java End-of-file

問題網址:https://www.hackerrank.com/challenges/java-end-of-file/problem

問題重點:

Scanner.hasNext()  Returns true if this scanner has another token in its input.

Scanner.hasNextLine()  Returns true if there is another line in the input of this scanner.

while(boolean)迴圈使用


因hasNext最後一行為false故不進迴圈,再加印一個最後一行。

[HackerRank](1)Java Output Formatting

題目網址 https://www.hackerrank.com/challenges/java-output-formatting/problem?h_r=next-challenge&h_v=zen

練習主軸:輸出格式化

轉換符說明示例
%s字符串類型“mingrisoft"
%c字符類型‘m’
%b布爾類型true
%d整數類型(十進制)99
%x整數類型(十六進制)FF
%o整數類型(八進制)77
%f浮點類型99.99
%a十六進制浮點類型FF.35AE
%e指數類型9.38e+5
%g通用浮點類型(f和e類型中較短的)
%h散列碼
%%百分比類型%
%n換行符
%tx日期與時間類型(x代表不同的日期與時間轉換符)

%-15s : -號代表從左邊輸入字串(若不寫則預設為向右對齊)。15為指定長度 s為字串

%03d:需要3位數10進位數字並向左補零

範例解答: