package hello;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
Scanner in = new Scanner(System.in);
System.out.println(in.nextLine());
}
}
---------------------------------------------------
Scanner :做輸入。
package hello;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("你好");
Scanner in = new Scanner(System.in);
System.out.println("echo:" + in.nextLine());
}
}
--------------------------------------------------------------
+ :連接兩個字符串;其中一個可以是固定的,另一個可以像這個輸入的
package hello;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("你好");
// Scanner in = new Scanner(System.in);
// System.out.println("echo:" + in.nextLine());
System.out.println("2+3=" + 5);
}
}
------------------------------------------------------------
+ :連接兩個字符串,其中一個是字符串,會將另一個轉化為字符串處理。
package hello;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("你好");
// Scanner in = new Scanner(System.in);
// System.out.println("echo:" + in.nextLine());
System.out.println("2+3="+5);
System.out.println("2+3="+2+3);
System.out.println("2+3="+(2+3));
System.out.println(2+3+"=2+3="+(2+3));
}
}
-------------------------------------------------------
() :做計算,改變優先級。