面试题2 机试

来源:互联网 发布:淘宝子账号怎么删除 编辑:程序博客网 时间:2024/06/06 11:44

【1】冒泡排序


int[]a = {13, 45, 2,5};

      inttemp = 0;

      for (inti=0; i<a.length -1; i++) {

        for (intj=0; j<a.length -1 -i; j++) {

           if (a[j] > a[j+1]) {

              temp= a[j];

              a[j]= a[j+1];

              a[j+1]= temp;

           }

        }

       

      }


【2】 单列

public class Test06 {

   private Test06(){}//第一步构造私有

  

   private static Test06 t = null; // 定义一个对象为空

  

   public static Test06getTest06(){  // 指定静态方法返回对象

      if(t ==null){

         t = new Test06();

      }

      return t;

   }

}


【3】列出指定目录下所有的文件


publicstaticvoidmain(String[]args){

      FilesrcFile=newFile("E://pic");

      Test.listFile(srcFile);

   }

  

   publicstaticvoid listFile(Filefile) {

      File[]listFiles= file.listFiles();

      for (Filefile2 : listFiles) {

        if (file2.isDirectory()) {

           listFile(file2);

        }else{

           System.out.println(file2.getName());

        }

      }

   }


【4】编写一个java多线程,每100毫秒执行一次,输出线程的名称

Thread thread =new Thread(){

        @Override

        publicvoid run() {

           while(true){

              try {

                 Thread.sleep(100);

                 System.out.println(Thread.currentThread().getName());

              }catch(InterruptedExceptione) {

                 e.printStackTrace();

              }

           }

          

        }

      };

       启动线程

      thread.start();


【5】外连接

select * from a left join b on a.co11=b.col1


数据库分页取10 到 20数据

select * from(select rownum r , * from t where r <=  20) where r >= 10

select * from t limit 10,10

原创粉丝点击