`

综合笔试题

阅读更多

1.写一个输入整数(如123456789)转换为二进制的程序,如输入32则输出1000000;

public class ConvertUtil{
     public static String doIntegerToBinaryString(intfrom){
         return Integer.toBinaryString(from);
     }
     public static int doIBinaryStringToInteger(String from){
         return Integer.parseInt(from,2)     
     }
}

 
2.写出对100个整数进行排序的程序,要求用两种不同的排序方法;

public class SortUtils
{
    public static bubuleSort(int[] source){
        for(int i=1;i<source.length+1;i++){
            for(j=source.length;j>=k;j--){
                if(source[j]<source[j-1])
                {
                    swap(source,i,i-1)
                 }
            }
        }
    }
}

 


3.写出一个字符串替换程序如输入”Welcome to comp”,将“co”替换成”abc”,即为” Wel abcme to abcmp”,要求不能作任何系统提供的函数如strrepalce等。

public class test{ 

    public test(){} 

  // 替换字符串函数  
  // String strSource - 源字符串  
  // String strFrom   - 要替换的子串  
  // String strTo     - 替换为的字符串  
  public static String replace(String strSource, String strFrom, String strTo)  
 {  
      // 如果要替换的子串为空,则直接返回源串  
      if(strFrom == null || strFrom.equals(""))  
          return strSource;  
      String strDest = "";  
      // 要替换的子串长度  
      int intFromLen = strFrom.length();  
      int intPos;  
      // 循环替换字符串  
      while((intPos = strSource.indexOf(strFrom)) != -1)  
      {  
          // 获取匹配字符串的左边子串  
          strDest = strDest + strSource.substring(0,intPos);  
          // 加上替换后的子串  
          strDest = strDest + strTo;  
          // 修改源串为匹配子串后的子串  
          strSource = strSource.substring(intPos + intFromLen);  
      }  
      // 加上没有匹配的子串  
      strDest = strDest + strSource;  
      // 返回  
      return strDest;  
  }  
 

 
4.设计数据库中有两个表,当主表中的一条记录删除时,副表中的相关记录全部自动删除。

delete from 副表 where 主表号 in(select 主表号 from 主表 where 条件)
delete from 主表 where 条件;

 
5.写两个类,子类中的方法在父类中实现。

简单


6.从数据库中查一个表,将表中的所有数据输出到磁般中的一个文件中。

Class.forName()->conn=DriverManager.getConnection("url",userName,password)->stm=conn.createStatement()->ResultSet rs=stm.createQuery("sql")

 

FileWriter fw=new FileWriter(new File("文件名")) ->rs.next ->fw.write(rs.getXXX())
7.用vb或其它写一个stock server和clinel通讯的例子;


8.一个线通讯的题,记不清了!
9.写一个父线程控制线程运行的例子。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics