一.单例模式
public class Singleton {
private static Singleton instance;
private Singleton() {
}
public static Singleton getInstance() {
if(instance == null) {
instance = new Singleton();
}
return instance;
}
}
二.对Integer[] inteArr={5,9,1,4,1,2,6,3,8,0,7}进行排序
我选择的是冒泡法:
int[] inteArr={5,9,1,4,1,2,6,3,8,0,7};
int inteArrLenght = inteArr.length;
int i = 0, j = 0;
Integer temp = null;
Integer[] tempArr = null;
for(i = 0;i<inteArrLenght;i++) {
for(j = i+1;j<inteArrLenght;j++) {
if(inteArr[i] > inteArr[j]) {
temp = inteArr[i];
inteArr[i] = inteArr[j];
inteArr[j] = temp;
}
}
}
for(int x :inteArr) {
System.out.println(inteArr[x]);
}
三.设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1;
public static void main(String[] args) {
for(int i = 0;i<2;i++) {
new Thread(addRunnable).start();
new Thread(substractRunnable).start();
}
}
static int j ;
public synchronized static void add() {
++j;
System.out.println("add==>" +j);
}
public synchronized static void substract() {
--j;
System.out.print("substract==>" +j);
}
static Runnable addRunnable = new Runnable() {
public void run() {
add();
}
};
static Runnable substractRunnable = new Runnable(){
public void run() {
substract();
}
};
四.数据库知识
员工基本信息表 user_info
id Int(5) | name Varchar(10) | age Varchar(3) | birthday Date |
1 | 张三 | 27 | 1982-11-21 |
2 | 李四 | 28 | 1981-09-12 |
3 | 王五 | 29 | 1980-02-07 |
4 | 王五 | 29 | 1980-02-07 |
员工迟到信息表 late_info
id Int(5) | userid Int(5) | latedate Date |
1 | 1 | 2008-11-03 |
2 | 1 | 2008-11-04 |
3 | 3 | 2008-11-05 |
4 | 4 | 2008-11-06 |
根据以上两张表信息,完成以下问题:
1. 查询张三的年龄
2. 找出1981年10月之前出生的员工
3. 更新李四的年龄为29岁
4. 找出迟到两次以上的员工ID
5. 删除重复的员工信息
答案:
1 select age from user_info where name=’张三’
2 select * from user_info where birthday < to_date(‘1981-10-01’,’yyyy-MM-dd’)
3 update user_info set age=29 where name=’李四’
4 select userid from late_info group by userid having count(userid)>1
5 delete from user_info t1 where t1.rowid > (select min(t2.rowid) from user_info t2 where t2.name = t1.name);
或者
creat table user_info_tmp (select distinct * from user_info);//创建临时表
truncate table user_info;//清空用户表记录
insert into user_info select * from user_info _tmp;//将临时表中的数据插回来
drop user_info _tmp;//删除临时表
五。
String str = “How are you”;
写一段程序,控制台打印出 “you are How”
答案: public static void main(String[] args) {
String str = "How are you";
String[] strArr = str.split(" ");
for(int i = strArr.length -1; i>=0; i--) {
System.out.println(strArr[i]);
}
}
六.
给定一个数组,
String[] before = new String[]{"a","b","a"};
完成以下方法,删除重复的元素,并返回处理后的数组。
public static String[] deleteDup(String[] before) throws Exception {
//TODO
}
答案:
public static String[] deleteDup(String[] before) throws Exception {
Set<String> set = new HashSet(Arrays.asList(before));
String[] after = set.toArray(new String[set.size]);
return after;
}