乱七八糟的备份
package org.lxh.demo16.common;//import java.awt.List;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.Random;/*** implement file: Tfrk.java* desc: 給一個大小為100的(整型)數組,分配0-1000的隨機數100個,* 但這100個數不能重復,然后把它從小到大排序,并輸出來。(時間10分鐘)* @author hemmingway <hemmingway@163.com>**/
public class Tfrk {//Singletonprivate static Tfrk instance = null;//setter & getterpublic static void setInstance(Tfrk instance) {Tfrk.instance = instance;}public static Tfrk getInstance() {if (instance == null)Tfrk.setInstance(new Tfrk());return instance;}/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stub//采用插入排序法, 產生一個隨機數就插入,插入的過程排除重復數字的插入即可Random random = new Random();int[] arrayList = new int[101];int len; //動態記錄已分配的數組長度int j;//initializationarrayList[0] = Math.abs(random.nextInt() % 1000);len = 1;while(true) {int num= Math.abs(random.nextInt() % 1000); for(j = len-1; j > -1 && num < arrayList[j]; j--) ; //檢查重復的數字if( (j == -1 ) || ( j > -1 && num > arrayList[j]) ){for(int tmp = len-1; tmp > j; tmp-- ){arrayList[tmp+1] = arrayList[tmp];}arrayList[j + 1] = num;len++;}//隨機分配100個后,就跳出,不再分配if (len > 99) break;} // end while(true)//打印輸出for (int i = 0; i < 100; i++){System.out.println( "arrayList[" + i + "]: " + arrayList[i]);}//what's the error?short s1 = 1;//s1 = s1 + 1; //cannot convert from int to shorts1 = (short) (s1 + 1);System.out.println(s1);//what's the out put?System.out.println(Math.round(11.5) + ", " + Math.round(-11.5));//how many String Object?@SuppressWarnings("unused")String ss = new String("XYZ");//JDK 1.7, where is goto syntax?//給出一個 runtime exception//System.out.println(arrayList[101]); //java.lang.ArrayIndexOutOfBoundsException: 101//接口與抽象類//接口可以繼承接口。抽象類可以實現(implements)接口,//抽象類可繼承實體類,但前提是實體類必須有明確的構造函數。//容器@SuppressWarnings("unused")List<String> lst; //Collection<E>//List的實現有ArrayList 和 Vectorlst = new ArrayList<String>();@SuppressWarnings("unused")Set<String> set; //Collection<E>@SuppressWarnings("unused")Map<String, String> map; //nothing///@SuppressWarnings("unused")int ll = arrayList.length; //數組的length屬性String str = "some test";@SuppressWarnings("unused")int sll = str.length(); //String有length方法//public final class String//implements java.io.Serializable, Comparable<String>, CharSequence/try{@SuppressWarnings("unused")short s2 = 3;return;}catch(Exception e){e.printStackTrace();}finally{}}}
總結
- 上一篇: 一道3G门户的面试题 (Java)
- 下一篇: 京东:要让五十四万员工过上更有尊严的工作