2011年4月5日

java basic(1)

轉自 http://caterpillar.onlyfun.net/Gossip/JavaGossip-V1/JavaGossip.htm

output
System.out.println("Hello! World!");
System.out.printf("%s! Welcome to Java!\n", "caterpillar");

get input
using Scanner
(import java.util.Scanner;)
Scanner scanner = new Scanner(System.in);
System.out.print("Please input your name: ");
System.out.printf("Hello! %s!", scanner.next());
// .nextFloat() .nextBoolean() .nextLine()....

using BufferedReader
(import java.io.*; )
public static void main(String[] args) throws IOException
{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("請輸入一列文字: ");
String text = buf.readLine();
System.out.println("您輸入的文字: " + text);
}


variable
type variable_name; //type ={int , float, char, bool , double ...}
final type variable_name = **** ; // a constant

comparer operator
> ,>= ,< ,<= ,==

logical operator
&& , || , !

bitwise operator
& , | , ^ , ~

logic
if...else
switch
for
while

================================


沒有留言:

張貼留言