`

经典题目

 
阅读更多

     a.  随机产生2位到10位不等的并且只包含和必须包含数字和字母的字符串 99 条。
      b.  把他们存储到线程安全的数据集合中。
      c.  需要使用设计模式中的单实例模式(单例中包含排序方法,此单例必须是多线程下是安全的)。
      d.  对产生的字符串进行排序:冒泡或者快速排序方法(如果字符串前面的字符相等就比较后面的字符)。
      e.  把结果打印到控制台,每四个字符串为一行,并且上下两行中的每个字符串第一位都要对齐,每行字符串之间要有间隔。

 

 


public class Test1{
 private static  final  int  LENGTH=14;
 private static Test1 instance=null;
 private Test1(){}
 public static Test1 getInstance(){
    if(null==instance){
   instance=new Test1();   
    }
    return instance;
 }
 static int[] num=new int[10];
 static char[] word=new char[26];
 public void init(){
    for(int i=0;i<num.length;i++){
     num[i]=i;
    }
    char w='a';
    for(int i=0;i<word.length;i++,w++){
     word[i]=w;
    }
 }
 
 public List<String> rdPwd(int LENGTH){
  List<String> alyList=new ArrayList<String>();
  StringBuffer sb=new StringBuffer();
  for(int i=0;i<LENGTH/2;i++){
   int numi=new Random().nextInt(9);
   int wordi=new Random().nextInt(25);
   sb.append(word[wordi]);//
   sb.append(num[numi]);
  }
  alyList.add(sb.toString());
  return alyList;
 }
 public static void main(String[] args) {
  
  Test1 t=Test1.getInstance();
  t.init();
  List<String> list=t.rdPwd(14);
  for(int i=0;i<list.size();i++){
    System.out.println(list.get(i)); 
  }
  
  Iterator<String> it=list.iterator();
  while(it.hasNext()){
          System.out.println(it.next());
  }
 }
   
}

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics