我现在用windows 所以用eclipse java实现
代码如下:
- package search;
- import java.util.Random;
- /*
- * 遍历一个随机字符串,并依次输出每个字符
- */
- public class search {
- //随机生成一个10-20位的字符串
- public static void main(String[] args) {
- //字符集合为数字 小写英文字母 大写英文字母
- String charCollection = new String("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
- String string = new String();
-
- Random random = new Random();
-
- charCollection.length();
- int index = 0;
- int length = random.nextInt(10)+10;
-
- for(int i =1;i<=length;i++)
- {
- index = random.nextInt(charCollection.length()-1);
- string = string + charCollection.charAt(index);
- }
- System.out.println(string);
- //完整遍历并打印出每个字符
- for(int i =0;i<length;i++)
- {
- System.out.print(string.charAt(i));
- System.out.print(' ');
-
- }
- }
- }
复制代码
|