452,888 views
23 votes
23 votes
Write a for loop to populate array userGuesses with NUM GUESSES integers. Read integers using Scanner. Ex If NUM GUESSES is 3 and user enters 9 5 2, then userGuesses is 19, 5, 2) 1 import java til. Sca nner 3 public class Store Guesses 4 public static void main (string args) Scanner SCnr new Scanner (System in final int NUM GUESSES int[] user Guesses new int[NUM. GUESSES] int 0; Your solution goes here 10 for (i 03 i NUM GUESSES ++i){ 11 user Guesses [i] scnr.nextInt 12 13 14 15 for (i 0; i NUM GUESSES ++i) 16 System.out print (u 17 18 19 for (i 0; i NUM GUESSES ++i)t 20 System Ou print (userGuesses[i] 21 Run X Testing for 12, 4, 6) 2 4 6 Expected output Your output 2 4 6 2 4 6 Tests aborted

User Prashant Puri
by
2.8k points

1 Answer

28 votes
28 votes

Answer:

import java.util.Scanner;

public class StoreGuesses {

public static void main (String [] args) {

Scanner scnr = new Scanner(System.in);

final int NUM_GUESSES = 3;

int[] userGuesses = new int[NUM_GUESSES];

int i = 0;

for (i = 0; i < NUM_GUESSES; ++i){

userGuesses[i] = scnr.nextInt();

}

for (i = 0; i < NUM_GUESSES; ++i){

System.out.print(userGuesses[i] + " ");

}

}

}

/*

Output:

2 4 6

2 4 6

*/

User KJF
by
3.2k points