I have a String[50] that contains 50 characters, those characters need to be placed in a String[10][10] using (int)(Math.random() * 3) so the loop would go through the entire matrix placing the characters in the last position+whatever math.random gets. These questions that teachers ask that limits the way you can answer them drives me nuts.
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
System.out.println("Type a phrase.");
String phrase = entrada.nextLine();
while (frase.length() > 50) {
System.out.println("The phrase has to be less than 50 characters. Try again.");
phrase = entrada.nextLine();
}
int carac = phrase.length();
String[] vector = new String[carac];
for (int i = 0; i < carac; i++) {
vector[i] = String.valueOf(phrase.charAt(i));
System.out.print(vet[i]);
}
int position = 0;
String[][] matrix = new String[10][10];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
position = (int) (Math.random() * 3);
matrix[i][j] = vet[i] //this part doesn't make any sense, I'm stuck here.
}
}
}
Example of desired output https://imgur.com/a/Z15cBpW
Aucun commentaire:
Enregistrer un commentaire