自己總結著玩
1.基本框架
public class HelloWorld{
?? ?public static void main(String[] args){
?? ??? ?
?? ?}//類名用大寫字母開頭?
}?
2.輸入:
(1)Scanner:可讀取各種類型,字符串相當于cin>>;
Scanner a=new Scanner(System.in);?
?? ?Scanner(Syetem.in)讀取鍵盤上的數據;
(2) BufferedReader:讀取文本
?? ?
3.輸出:
(1)System.out.println("%8.2f")自動換行?? ??
(2)System.out.print()不會自動換行
(3)System.out.printf()格式輸出
4. (1)scanner.nextInt() 讀取整數?
(2)scanner.nextDouble()讀取浮點數
(3) scanner.nextLine()讀取字符串
(4)scanner.next()讀取字符?
5.整型:
int()
short()
long()
byte()
6.浮點型:
float()
double()
7.char()類型
表示單個字符,用‘’標注""表示字符串
String字符串?
8.boolean類:有兩個值:false,true?
9.變量與常量:?
常量:final double c=2.0
枚舉類型:enum Season {
? ? SPRING, SUMMER, AUTUMN, WINTER
}
enum Color?
{?
? ? RED, GREEN, BLUE;?
}?
??
public class Test?
{?
? ? // 執行輸出結果
? ? public static void main(String[] args)?
? ? {?
? ? ? ? Color c1 = Color.RED;?
? ? ? ? System.out.println(c1);?
? ? }?
}
10.數學函數:
Math.pow()
Math.sqrt()
Math.sin/cos/tan/atan/atan2()
Math.exp/log/log10()
Math.PI/E;
11.數值的強制轉換,賦值(參考c)
12.條件運算:x>y?x:y;
switch,if else ?? ??? ??
13.字符串:String a=""
substring可從字符串中提取一個子串
String s=a.subsring(0,3(不包括))?
可用+拼接:
String a="";
String b="";
String c=a+b;中間無空格
s.equals(t)檢查s與t字符串是否相等
null檢查是否為空串
14.算字符串長度:
int n=str.length();
15.構造字符串:
StringBuilder a=new StringBuider();
a.append(c);
a.append(b);
String d=a.toString();?
16.大數:?
BigInteger()任意精度整數?
BigDecimal()任意精度浮點數?
BigInteger a=BigInteger.value0f(100)將普通的化為大數
BigInteger a=b.add(c)//a=b+c
BigInteger a=b.multiply(c)//a=b*c
17.數組:?
int a[]/int[] a
int[] a=new int[100]?
for each循環:
18.拷貝:
int[] a=Arrays.copy0f(b,2*b.lenth);
19.數組排序:Arrays.sort(a)
20.多維數組:
int[][] a=new int[100][100];