自己总结着玩
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];