当前位置:首页 > JAVA面试题集
for (int i=0;i { al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1)); System.out.println(\ } } public void SortIt() { Integer tempInt; int MaxSize=1; for(int i=1;i { tempInt = (Integer)al.remove(i); if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue()) { al.add(MaxSize,tempInt); MaxSize++; System.out.println(al.toString()); } else { for (int j=0;j { if (((Integer)al.get(j)).intValue()>=tempInt.intValue()) { al.add(j,tempInt); MaxSize++; System.out.println(al.toString()); break; } } } } System.out.println(\ for(int i=0;i { System.out.println(\ } } public static void main(String[] args) { InsertSort is = new InsertSort(10,100); is.SortIt(); } } JAVA类实现序例化的方法是实现java.io.Serializable接口 Collection框架中实现比较要实现Comparable 接口和 Comparator 接口 7、编程:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是“我ABC+汉的半个”。 答:代码如下: package test; class SplitString { String SplitStr; int SplitByte; public SplitString(String str,int bytes) { SplitStr=str; SplitByte=bytes; System.out.println(\ } public void SplitIt() { int loopCount; loopCount=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/Split Byte+1); System.out.println(\ for (int i=1;i<=loopCount ;i++ ) {
共分享92篇相关文档