1、冒泡排序
public class Demo{
public static void main(String[] args){
int[] a = {5,3,4,23,1,2,45,67,87,34};
int[] sort = sort(a);
System.out.println(Arrays.toString(sort));
}
public static int[] sort(int[] arrays ){
//临时变量
int temp = 0;
//外部循环
for(int i = 0; i < arrays.length -1; i++){
boolean flag = false;
//内部循环
for(int j = 0; j < arrays.length - 1 - i; j++){
if(arrays[j] > arrays[j + 1]){
temp = arrays[j];
arrays[j] = arrays[j + 1];
arrays[j + 1] = temp;
flag = true;
}
}
if(!flag){
break;
}
}
return arrays;
}
}
二、基本数据类型
byte
short
int
long
float
double
char
boolean
1
2
3
4
5
6
7
8
数据类型名称 占用字节 默认值
byte 1 0
short 2 0
int 4 0
long 8 0L
float 4 0.0F
double 8 0.0D
char 2 \u0000(空格)
boolean 1或者4 false
二、进制表示
//二进制0b 八进制0 十进制 十六进制0x 0~9 A~F
//二进制0b
int aa = 0b10; //2
//十进制
int a1 = 10; // 10
//八进制
int b1 = 010; // 8
//十六进制
int c1 = 0x10; //16
1
2
3
4
5
6
7
8
9
三、字符
//所有的字符本质还是数字
//编码 Unicode Excel表 之前表的大小65536 2的16次方 现在更大了
//Unicode 底层这样表示 U0000 - UFFFF
char v = 'a';
System.out.println(v);//a
System.out.println((int)v);//97
char n = '中';
System.out.println(n);//中
System.out.println((int)n);//20013
char m = '\u0061';
System.out.println(m);//a
1
2
3
4
5
6
7
8
9
10
11
12
四、转义字符
//还有很多 可以自己去发掘
// \t 制表符
// \n 换行
System.out.println("hello\tworld");//hello world
System.out.println("hello\nworld");//hello
// world
1
2
3
4
5
6
五、位运算
A = 0010 1011
B = 0110 1101
//&与运算 遇0则0 都是1则为1
A & B =0010 1001
//|或运算 遇1则1 都是0则为0
A | B = 0110 1111
//^ 异或 相同为0 否则为1
A ^ B = 0100 0110
//~取反
~B = 1001 0010
//效率极高
//<< 左移 把数字乘以2
//>> 右移 把数字除以2
16 8421
0000 0000 //0
0000 0001 //1
0000 0010 //2
0000 0011 //3
0000 0100 //4
0000 0101 //5
0000 0110 //6
0000 1000 //8
0001 0000 //16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
六、逻辑运算
boolean a = true;
boolean b = false;
//&& 短路与 遇false则false,两个都为真,结果才为真
System.out.println(a && b); // false
//|| 短路或 遇true则true,有一个为真,结果就为真
System.out.println(a || b); // true
// ! 取反 取相反的结果 是真取假,是假取真
System.out.println(!(a && b)); //true