2013年8月12日 星期一

學習輸入

http://openhome.cc/Gossip/JavaGossip-V1/UserInput.htm

public class Hwlloworld{
    public static void main (String[] args)
{
         Scanner scanner = new Scanner (System.in);
         System.out.println ("Please enter your name: ");
         System.out.printf ("Hello %s!", scanner.next( ));
}

Scanner需大寫

-----------------------------------------------------------

Scanner scanner = new scanner (System.in);

Scanner是指輸入端
java需要輸入端

new是指產生
java絕大多數物件都需要產生

所以上述的意思就是
Scanner輸入了scanner產生了新的scanner
而輸入的內容放在System.in

或者這樣解釋
有個Scanner叫做scanner
這個scanner是個新的接在System.in的Scanner

所以也可以寫成

Scanner a = new Scanner (System.in);

----------------------------------------------------------

%s的意思是formatter placeholder
代表一個字串
這是formatter系列才有用的東西. print"f"  <---

所以這個的意思是

Hello! [這邊要印一個字串]   <---跟編譯器說這件事情

後面就會與編譯器說,那個東西就是 scanner.next()
scanner.next()是指他會去找你輸入的內容(System.in)

沒有留言: