2016-12-26 60 views
1

在第一次練習coding practices first exercise我用java如何獲得practice.geektogeek中的輸入?

我在測試輸入進入:

1 
5 
1 2 3 2 1 

然後,我只是想打印什麼,我在args有這麼主我做的:

System.out.println(Arrays.toString(args)); 

但我得到的是:

[ad6d0e2c0388c211a37a93f12dd4ea078] 

我的輸入在哪裏?我如何得到它?

+4

你必須從'stdin'不'args'讀它。 –

回答

1

問題中的輸入不是命令行參數,而是程序運行後傳遞給stdin的輸入。您可以從System.in得到它,例如,通過使用Scanner

Scanner sc = new Scanner(System.in); 
while (sc.hasNextLine()) { 
    System.out.println(sc.nextLine()); 
}