import java.util.Random; public class randomChars { public static void main(Stri
ID: 3612409 • Letter: I
Question
import java.util.Random;
publicclass randomChars
{
publicstatic voidmain(String[] args){
Random gen =new Random();
int keyLength, maxLength = 26, minLength=5;
boolean[]used = new boolean[maxLength];
String key = "";
int i,j,usedcount=0;
int creationCount =0;
for(i=0;i<maxLength;i++){
used[i]=false;
//creationCount++;
}
keyLength =gen.nextInt(maxLength-minLength)+minLength;
while(usedcount<keyLength){
j=gen.nextInt(maxLength);
if(!used[j]){
used[j]=true;
usedcount++;
key+=(char)(j+65);
}
}
System.out.println("Key = " +key);
}
}
Explanation / Answer
please rate - thanks changes is red import java.util.*; public class randomkey { public static void main(String[] args) {Random random = new Random(); int keylength,maxlength=26,minlength=5; boolean []used=new boolean[maxlength]; String key; int i,j,k,usedcount; for(k=0;kRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.