Please how do I generate a string of random numbers in Java in this formatted order. The string is 5 characters in length (as specified in the format below)
string-string-integer-integer-integer
Every single one of the characters is to be random but in the format specified above. Please help. Thanks.
This is code I am currently having issues with. Please how do I improve it. Thanks.
import java.util.Random;
public class HelloWorld{
public static void main(String []args){
Random r = new Random();
String[] alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int[] number = {1,2,3,4,5,6,7,8,9,0};
for (int i = 0; i < 5; i++) {
System.out.printf("%s,%s,%d,%d,%d\n",
alphabet[i].charAt(r.nextInt(alphabet.length())),
number[i].charAt(r.nextInt(number.length())) );
} // prints 50 random characters from alphabet
}
}
Aucun commentaire:
Enregistrer un commentaire