随机生成string.

80酷酷网    80kuku.com

  随机
随机生成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??

高手指点一下.




分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: