mardi 29 septembre 2020

How do I make a random int into a variable I can use and compare in Java?

its not great code I know but I need help at line 30 with if (guess == roll) im trying to make it if you guess the number right it will say you win and if not it will not say you win.

import java.util.Random;
import java.util.Scanner;

public class diceGame 
{
 public static void main(String[] args) 
 {
    Scanner scan = new Scanner(System.in);
    diceGame test = new diceGame();
     
    System.out.println("Number of rolls?: ");
    int numRoll = scan.nextInt();
    
    System.out.println("Gues the number/most common number: ");
    int guess = scan.nextInt();
     
     Random rand = new Random();
    
            for(int i = 0; i < roll.length; i++)
            {
            roll[i] = rand.nextInt(6)+1;
            }
            
        for(int i = 0; i < roll.length; i++)
        {
        System.out.print(roll[i] + ", ");
        }
 
        
        if (guess == roll)
        {
            System.out.println("Good job you guess correct");
        }
        else
        {
            System.out.println("You did not guess correct");
        }
 } 
    
 }



Aucun commentaire:

Enregistrer un commentaire