乱七八糟的备份

时间:2022-12-13 15:57:36


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 {
//Singleton
private static Tfrk instance = null;

//setter & getter
public 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;

//initialization
arrayList[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 short
s1 = (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 和 Vector
lst = 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{

}




}



}