Computer Science, asked by ramandeepkaur1995, 7 months ago

Write a java program that generates a random integer between 1 and 0 (and display the
integer), and then asks the user to guess 1 or 0 (input 1 or 0). The game repeats 5 times.
Compare the user input with the generated random number each time. Every time the
user guesses it right, display “bingo”.

Answers

Answered by Oreki
1

import java.util.Scanner;

public class GuessGame {

   public static void main(String[ ] args) {

      for (int i = 0; i < 5; i++) {

           System.out.print("\nGuess 1 or 0 - ");

           int guess = new Scanner(System.in).nextInt( ),

                   randomNumber = (int) (Math.random( ) * 2);

           System.out.println(guess == randomNumber ? " Bingo!" : " Nope!");

       }

   }

}

Answered by anindyaadhikari13
1

Question:-

Write a java program that generates a random integer between 1 and 0 and ask the user yo guess 1 or 0. The game repeats 5 times. Every time the user guesses right, display bingo.

Program:-

import java.util.*;

class Random

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int i=1;

while(i++<=5)

{

System.out.print("Enter your number (1 or 0): ");

int n=sc.nextInt();

int r=(int)(Math.random()*2);

System.out.println((r==n)?"Bingo!! ": "Wrong Choice. ");

}

}

}

Similar questions