Ich habe ein String-Array namens teams und ein int-Array namens nums erstellt. Jede Ganzzahl im Array num entspricht einem Team im Array string.Java While Loop & 1D Array
Ex:
Montreal Canadiens = 1, = Chicagao Blackhawks 2 usw.
Ich brauche zufällig Nummern zur Auswahl 1-10 ([] num int entspricht), und dies Die Schleife muss fortgesetzt werden, bis jedes Element im Integer-Array einmal aufgerufen wird. Am Ende der Schleife bedeutet dies, dass jedes Team im String-Array einmal aufgerufen wird. Dies muss durch eine while-Schleife erfolgen. Ich kann nicht herausfinden, wie man genau eine Schleife erstellt, die das tun würde.
import java.util.Scanner;
public class Question1 {
public static void main(String[] args) {
//declare scanner
Scanner keyboard= new Scanner (System.in);
//display opening message
System.out.println("= 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 =");
System.out.println("= 0 0 =");
System.out.println("= 0 NHL Miniature Hockey Puck Vending Machine 0 =");
System.out.println("= 0 0 =");
System.out.println("= 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 =");
System.out.println("");
System.out.println("");
System.out.println("Hello, what is your first name? ");
//read user input
String name = keyboard.nextLine();
//Welcome message
System.out.println("Welcome " + name + "! Let's see how much money you will need to spend to get all of the pucks.");
//declaring 10 teams in a 1D array
String[] teams = {"Montreal Canadiens","Chicago Blackhawks","Boston Bruins","Toronto Maple Leafs","Vancouver Canucks","Ottawa Senators","Pittsburgh Penguins","Calgary Flames","New York Rangers","Edmonton Oilers"};
int[] nums = {1,2,3,4,5,6,7,8,9,10};
//random number from 1-10
while (
int RandomNum = (int)(Math.random()*10)+1;
Vergiss nicht, 'keyboard.close();' zu nennen :-) – mcuenez