[toc] ## System System內有兩個field, `in` 跟 `out` 分別是輸入/輸出流物件 ## 輸出 ### System.out.print 有兩個方法可用: `System.out.print(obj);` -> 就直接輸出 `System.out.println(obj);` -> 輸出, 換行 引數可以是任何資料型別。 ## 輸入 ### Scanner 建立一個Scanner物件, 內含很多方法。 ```java Scanner sc = new Scanner(System.in); sc.nextInt() // int sc.nextByte() // byte sc.nextLong() // long sc.nextShort() // short sc.nextBoolean() // boolean sc.nextFloat() // float sc.nextDouble() // double sc.nextLine() // 輸入一整行的"字串" sc.next() // 輸入"字串", 以空格區分 ``` --- ### 緩衝Reader+輸入流Reader 一次讀一整行, 執行速率較快。 ```java BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.nextLine(); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up