掌上明珠面试总结

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 106 收藏 0 点赞 0 评论 0

1. 分配一个5列6行的字符串数组.
2. 写出下面这段程序的输出
try
{
int i=0;
int i2=3/i;
}catch(ArithmeticException ae){
System.out.println(“数学计算错误”);
}catch(Exception e){
System.out.println(“通用错误”);
}finally{
System.out.println(“计算完成”);
}
3. 我们希望下面这段程序能顺序打出0到9十个数字,请指出错误:
public class Demo{
ArralList queue=new ArrayList();
int nextID=0;
Object lock=new Object();

public static void main(String[] args)
{
new Demo().start();
}
public void start()
{
new Producer().start();
new Producer().start();
new Consumer().start();
new Consumer().start();
}
class Producer implements Runnable{
public void run()
{
while(nextID<10) { queue.add(new Integer(nextID++)); synchronized(lock){ try{ lock.notifyAll(); }catch(Exception e){ } } try{ Thread.sleep(1000); }catch(InterruptedException e){ } } } } class Consumer implements Runnable{ public void run(){ while(true){ if(queue.size()==0) { synchronized(lock) { try{ lock.wait(); } catch(Exception e){ } } } System.out.println(queue.remove(0)); } } } } 4. 完成下面的程序,把一个int值保存到byte数组中(高位在前). int i=13223; byte[] b=new byte[4]; 5. 请说明Map(映射表)和Set(集合)这两种数据结构的异同点. 6. 有一个GBK编码的文本文件c:/a.txt(<32k),请写出一段程序,读取它的内容显示在标准输出上. 7. 请完成下面的排序算法 public interface Comparable{ //Compare to another instance //@return >0 if this is larger,=0 if equal, <0 if this is smaller. public int compareTo(Object o); } public static void sort(Comparable[] arr){ ………… }

评论列表
文章目录