- 写出Runtime Exception
- NullPointerException
- NumberFormatException(继承IllegalArgumentException,字符串转换为数字时出现)
- ArrayIndexOutOfBoundsException(数组越界)
- StringIndexOutOfBoundsException(字符串越界)
- ClassCastException(类型转换错误)
- UnsupportedOperationException(该操作不被支持)
- ArithmeticException(算术错误)
- IllegalArgumentException(非法参数)
- ArrayList: 采用的是数组形式来保存对象的,这种方式将对象放在连续的位置中,所以最大的缺点就是插入删除时非常麻烦;
- LinkedList: 采用的将对象存放在独立的空间中,而且在每个空间中还保存下一个链接的索引 但是缺点就是查找非常麻烦 要从第一个索引开始;
3.StringBuilder,StringBuffer,Stirng的区别
- StringBuilder:不是线程安全的;
- String:的值是不可变的,这就导致每次对String的操作都会生成新对象,不仅效率低下,而且大量浪费有限的内存空间;
- StringBuffer:是可变类,和线程安全的字符串操作类,任何对它指向的字符串的操作都不会产生新的对象,自动增加容量;
4.设计模式
- 策略模式,
- 装饰模式,
- 观察者模式
- 适配器模式
- 模版本方法
- 单例模式
fib(n-1)+fib(n-2) (n>1);第一项和第二项都等于2;求出 斐波那契数列第n项(n>=1的自然数),要求用递归算法.
public static void main(String[] args) {
FindFile findfile= new FindFile();
List<File> fileList = findfile.getFiles(new File("d:\\test"), "txt");
for (File file : fileList) {
String fileName=file.getName().substring(0,file.getName().lastIndexOf("."));
System.out.println(fileName);
}
}
8.有三张表,
DROP TABLE IF EXISTS `b`;
CREATE TABLE `b` (
`boe_header_id` int(11) NOT NULL,
`boe_line_id` int(11) DEFAULT NULL,
`amount` varchar(11) DEFAULT NULL,
`type` varchar(11) DEFAULT NULL,
PRIMARY KEY (`boe_header_id`)
)
DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
`boe_header_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '单据头id',
`dept_id` int(11) DEFAULT NULL COMMENT '报账部门id',
`boe_date` varchar(11) DEFAULT NULL COMMENT '报账日期',
PRIMARY KEY (`boe_header_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
DROP TABLE IF EXISTS `c`;
CREATE TABLE `c` (
`dept_id` int(11) NOT NULL AUTO_INCREMENT,
`dept_name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`dept_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
编写sql查询出综合部门在2015年1月份报销费用类型为交通费的报账金额总和?
SELECT b.type,sum(b.amount) from b
LEFT JOIN a on b.boe_header_id=a.boe_header_id
LEFT JOIN c on a.dept_id=c.dept_id
where b.type='交通费' and c.dept_name='综合部' and a.boe_date='2015.1';
9.排序
/**
* 排序 从小到大排列
*
* @param arr
* @return
*/
public static int[] sorttArr(int[] arr) {
int temp;
for (int i = 0; i < arr.length-1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
return arr;
}
折半查找:先排序 -1 为没有找到,找到直接返回要找数字的位置
public int searchNum(int[] arr, int findNum) {
if (arr == null) {
return -1;
}
int start = 0;
int end = arr.length - 1;
while (start <= end) {
int middle = (start + end) / 2;
int middleNum = arr[middle];
if (findNum == middleNum) {
return middle;
} else if (findNum < middleNum) {
end = middle - 1;
} else {
start = middle + 1;
}
}
return -1;
}