一、位运算符
~ 取反 &按位与 | 按位或 ^按位异
<<左位运算符,>>右移运算符;无符号移位运算符
右移一位相当于除2取商 左移一位相当于乘2
package test;
public class Test {
public static void main(String[] args) {
int a=3*2*2;
int a1=3<<2;
int b=12/2/2;
int b1=12>>2;
System.out.println("a="+a);
System.out.println("a1="+a1);
System.out.println("b="+b);
System.out.println("b1="+b1);
}
}
二、多选择结构switch
switch语句,case标签必须是整数或者枚举,不能是字符串
例子:
`package test;
import java.util.Random;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//随机产生一个字母
int c ='a';
//产生一个0~25之间的整数
int a=(int)(26*Math.random());
//随机产生一个小写字母
char i=(char)(c+a);
//换行
System.out.println(i+" ");
//利用switch的穿越属性知道遇到break停止
switch (i) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("为元音字母");
break;
case 'y':
case 'w':
System.out.println("为半元音字母");
break;
default:
System.out.println("为辅音字母");
break;
}
}
}
` 递归结构(recur:重现,再来。递归:recursion)
递归的基本思想就是“自己调用自己
计算5的阶乘
package test;
public class Test {
//阶乘方法
public static long dg(int n){
if (n==0) {
return 1;
}else {
return n*dg(n-1);
}
}
public static void main(String[] args) {
long a=dg(5);
System.out.println(a);
}
}
例子2
package test;
public class Test {
//使用递归实现斐波那契 1 1 2 3 5 8 13
public static long dg(int n){
if (n==0) {
return 0;
}else if (n==1) {
return 1;
}
else if(n>1){
return dg(n-1)+(n-2);
}else{
return -1;
}
}
public static void main(String[] args) {
long a=dg(5);
System.out.println(a);
}
}
三、文件递归查找
package test;
import java.io.File;
public class Test {
//使用递归实现斐波那契 1 1 2 3 5 8 13
public static void dg(File f){
//判断文件是否存在
if (f.exists()) {
//判断文件是否为目录
if (f.isDirectory()) {
//如果是取得所有文件
File[] lf = f.listFiles();
if (lf!=null) {
for (File wj : lf) {
dg(wj);
}
}
}else{
//如果是目录打印所有文件
System.out.println(f.getAbsolutePath());
}
}
}
public static void main(String[] args) {
dg(new File(“F:/课堂视频”));
}
}
package test;
public class Maopao {
public static void main(String[] args) {
int b[]={1,5,99,75,20};
int temp;
for (int i = 1; i < b.length; i++) {
for (int j = 0; j < b.length-1; j++) {
if (b[j]>b[j+1]) {
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
for (int a : b) {
System.out.println(a);
}
}
}
package test;
public class wunao {
public static void main(String[] args) {
int b[]={1,5,99,75,20};
int temp;
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b.length; j++) {
if (b[i]
面向对象
Object 是java的根。
封装,继承,多态,抽象
封装作用:安全

继承:子类继承(extends )父类,子类就拥有了父类的非私有属性和方法(包含父类的父类)构造方法不能继承
java代码的运行顺序:先静态后动态,先父类后子类
多态:重写和重载
重写:子类继承父类,子类方法名返回值和参数列表同父类一样,方法体不同
重载:在一个类中,方法名相同参数类型不同(顺序,类型,个数)
向上转型和向下转型
向上转型:创建一个子类的对象,将指针指向父类的引用。
Person p = new Student();
向下转型:把这个对象原本的样子给展示出来。
Student s = (Student)p;
this 对象本身,谁调用我,this就是谁
super 父类本身,指父类出面
final 最终的 最后的 不变的
修饰类 类不能被继承
修饰属性 变量变常量, 值不能改变
修饰方法 方法不能被重写
集合

HashMap
package com.map;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
/**
* HashMap
* @author Administrator
*
*/
public class HashMapDemo {
public static void main(String[] args) {
HashMap
package com.sxt;
import java.util.HashSet;
import java.util.Iterator;
public class HashSetDemo {
public static void main(String[] args) {
HashSet set=new HashSet();
//添加元素
set.add(“欧阳狗蛋”);
set.add(“慕容翠花”);
set.add(“诸葛栓子”);
set.add(“皇甫二丫”);
//for each 遍历元素
for (String s : set) {
System.out.println(s);
}
//删除
set.remove(“诸葛栓子”);
Iterator it = set.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}
package com.sxt;
import java.util.LinkedList;
/**
* 链式集合
* @author Administrator
*
*/
public class LinkdeListDemo {
public static void main(String[] args) {
LinkedList sd = new LinkedList();
sd.addFirst(“李三”);
sd.addFirst(“赵四”);
sd.addFirst(“王五”);
sd.addLast(“慕容狗蛋”);
System.out.println(sd);
//循环遍历
/*while (!sd.isEmpty()) {
System.out.println(sd.removeLast());
}*/
for (int i = 0; i < sd.size(); i++) {
System.out.println(sd.get(i));
}
for (String s : sd) {
System.out.println(s);
}
}
}
“`
未完待续。。。