随机生成string.

类别:Java 点击:0 评论:0 推荐:

随机生成string..

 class Str
  {
   
   public static void main(String args[])
   {
    char[] cc = new char[10];
      for (int i = 0; i<cc.length; i++)
      {
           while(cc[i]<'A' || cc[i]>'Z')//why using while not if? 为什么用while
                cc[i]=(char)(Math.random()*(int)'Z');
  
        //System.out.println(cc[i]);
    }//end for
    String str = new String("");
   
    for (int i = 0; i<cc.length; i++)
        str += cc[i];
       
         System.out.println(str);
   }
  }

    可生成一个固定长度的随机字母string..??如何让string的长度随机呢?还有就是为什么while而没有用if??

高手指点一下.

本文地址:http://com.8s8s.com/it/it10180.htm