Home > Back-end >  Java written title
Java written title

Time:11-27

Random number
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 System. The out. Println (str4 [I]);
}

}

Private static String [] mergeArray (String [] str1, String [] str2, String [] str3) {

ArrayList list=new ArrayList (a);
//get element
ArrayList List1=getdata (str1, 2);
ArrayList List2=getdata (str2, 3);
ArrayList List3=getdata (str3, 5);
List. The addAll (list1);
List. The addAll (list2);
List. The addAll (list3);
The return list. ToArray (new String [0]).

}
Private static ArrayList Getdata (String [] STR, int num) {
Random random=new Random();
ArrayList list=new ArrayList (a);
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 figures

CodePudding user response:

reference o f m response:
application: construct a strong password, contains two capital letters, three lowercase, five Numbers
thank you
  • Related