mercredi 5 décembre 2018

This code looks correct to me, but it isn't. What's wrong? [on hold]

The purpose of this code is to receive 4 different random numbers within different ranges based on the user input given. "Yes" should give 4 numbers between 1 and 56, and "No" should give 4 numbers between 1 and 51.

import java.util.Scanner;

public class RandomPerkSelector {

public static void main(String [] args){
  Scanner userInputReader = new Scanner(System.in);
  System.out.println("Are you playing as a survivor?");
while(true){
String userInput = userInputReader.nextLine();
  if(userInput.equals("Yes")){
    Random rand = new Random();
    int[] nums = new int[4];
    for (int i = 0; i < 4; i++) {
    int[i] = rand.nextint(57);
}
    break;
  }else if(userInput.equals("No")){
   Random rand = new Random();
   int[] nums = new int[4];
   for (int i = 0; i < 4; i++) {
   int[i] = rand.nextint(57);
}
    break;
  }else{
    System.out.println("This is a yes or no question.");
    continue; 
   }
  }
 }
}

My problem comes from the coding for the random numbers in both the "Yes" and "No" sections.

Random rand = new Random();
  int[] nums = new int[4];
  for (int i = 0; i < 4; i++) {
  int[i] = rand.nextint(57);

Random rand = new Random();
   int[] nums = new int[4];
   for (int i = 0; i < 4; i++) {
   int[i] = rand.nextint(52);

According to Codiva.io, the lines that have "int[i]" require ] and ;. I don't see why it says this, and even after all the searching I've done, I'm stumped.




Aucun commentaire:

Enregistrer un commentaire