Known to have three string array (all elements are not the same), provides a method, each call from 1, 2, 3 random made 2,3,5 elements in an array of returns a new array, random elements and the results are requested not to repeat
CodePudding user response:
Package com. Cn;import java.util.ArrayList;
import java.util.Random;
/* *
*
* random number
Known to have three string array (all elements are not the same),
Provide a method that each call from 1, 2, 3 random made 2,3,5 elements in an array component returns a new array of random elements and the results are requested not to repeat the
* @ author jack
*
*/
Public class Demo01 {
Public static void main (String [] args) {
String [] str1={" 1 ", "2", "3", "4", "5", "6", "7", "eight" and "9"};
Str2 String []={" 11 ", "12", "13", 14 ", "15", "16" and "17", "18", "19"};
String [] str3={" 21 ", "22", "23", "24", "25", "26", "27", "28", "29"};
String [] str4=mergeArray (str1 str2, str3);
//print run results
For (int I=0; i
}
}
Private static String [] mergeArray (String [] str1, String [] str2, String [] str3) {
ArrayList
//get element
ArrayList
ArrayList
ArrayList
List. The addAll (list1);
List. The addAll (list2);
List. The addAll (list3);
The return list. ToArray (new String [0]).
}
Private static ArrayList
Random random=new Random();
ArrayList
While (the list. The size () & lt; Num) {
String String=STR [random nextInt (STR) length)];
if(! List. The contains (string)) {
List. Add (string);
}
}
return list;
}
}
CodePudding user response:
Practical application: construct a strong password containing two capital letters, 3 lowercase letters, and five figuresCodePudding user response: