Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args){
- int randomNumber;
- Scanner scanner = new Scanner(System.in);
- Random random = new Random();
- String color;
- String guessedColor;
- int sum = 0;
- randomNumber = random.nextInt(5);
- switch (randomNumber)
- {
- case 0:
- color = "Red";
- break;
- case 1:
- color = "Green";
- break;
- case 2:
- color = "Blue";
- break;
- case 3:
- color = "Orange";
- break;
- case 4:
- color = "Yellow";
- break;
- default:
- color = "rzulty";
- break;
- }
- System.out.println(color);
- System.out.println("Guess the color");
- for (int i = 0; i < 10; i++)
- {
- guessedColor = scanner.nextLine();
- if (guessedColor.equalsIgnoreCase(color))
- {
- sum++;
- }
- }
- System.out.println("You guessed it " + sum + " times");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement