package com.imooc; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; public class StringSort { List <String> one; public StringSort(){ one=new ArrayList<String>(); } public static void main(String[] args) { // TODO Auto-generated method stub /* 1创建完List<String>之后,往其中添加十条随机字符串 2每条字符串长度为10以内的随机字符串 3每条字符串都为随机生成的字符,字符可以重复 4每条随机字符串不可重复*/ Random A=new Random(); List<String> one=new ArrayList<String>(); String B="1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz"; String string; for(int i=0;i<10;i++){ StringBuilder C=new StringBuilder(); do{ int D=A.nextInt(B.length()-1); int E=A.nextInt(10); for(int ii=0;ii<E;ii++){ C.append(B.charAt(A.nextInt(D)));} string =C.toString(); }while(one.contains(string)); System.out.println("成功添加第"+(i+1)+"个元素:"+string); one.add(string); } System.out.println("----------排序前------------"); for(String one1:one){ System.out.println(one.indexOf(one1) +one1); } System.out.println("-----------排序后-----------------"); Collections.sort(one); for(String one1:one){ System.out.println(one.indexOf(one1) +one1); } }}
请问关于这代码有什么会出现异常
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
at com.imooc.StringSort.main(StringSort.java:31)
这是关于java第三季中6.5的练习。
什么鬼_呀你
慕的地6079101
hy_wang
相关分类