课后练习代码分享
package randomStringSort; import java.util.Random; public class RandString { public String str; public int lenth; public RandString(){ Random rand = new Random(); this.lenth = rand.nextInt(10) + 1; StringBuilder sbd = new StringBuilder (); for (int i = 0; i<this.lenth ;i++){ char a; for (a='*';a<'0'||(a>'9'&&a<'A')||(a>'Z'&&a<'a')||a>'z';){ a = (char)(rand.nextInt(75)+48); } sbd.append(a); } this.str = sbd.toString(); 、 } }
《RandString.java》