如何從鍵盤讀值 並 output到command window上

 

// 記得要import Scanner

 

import java.util.Scanner

 

public class IO

 

{

 

  public static void main(String args []){

 

  Scanner input = new Scanner(System.in);

 

  int i = input.nextInt();

 

  System.out.println(i);}

 

 

整理一些Scannerconstructormethod

constructor

public Scanner(File source) 

throws FileNotFoundException

例:作file的輸入

public Scanner(String source) 

例:作字串的輸入

public Scanner(InputStream source) 

例:作基本資料型態的輸入

作為參數的 System.in 相當於 The "standard" input stream

method

boolean hasNextDouble()

當有下一個Double值輸入時,回傳true

Double可被換成

Boolean Byte float int line long short 或是直接只有hasNext()

Double nextDouble()

回傳輸入的double

Double可被換成

Boolean Byte float int line long short 或是直接只有next()

 

 

arrow
arrow
    全站熱搜

    vincint810923 發表在 痞客邦 留言(0) 人氣()