vendredi 3 septembre 2021

50 tries and 1 hasnt been the answer at all

This is coded in Java 15.0.2 and on netbeans 12.0LTS I would like to assume I coded this coin flip generator correctly but 0 is the only option that gives me correct, 1 never has. I don't know if I messed something up with Math.random or if i'm just that unlucky.

package pkgthis.thing;

import java.util.Scanner;
/**
 *
 * @author Student
 */
public class LabQuestion6 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        int coin = (int) (Math.random()*1);

        int choice;

        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Please choose 1 or 0: \n");

        choice = keyboard.nextInt();
        
        if (choice == coin) 
        {
            System.out.println("You are correct");  
        } 

        else 
        {
            System.out.println("You are incorrect");
        }
    }
    
}



Aucun commentaire:

Enregistrer un commentaire