Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package studies;
- import java.util.Scanner;
- import java.util.Random;
- public class Studies {
- public static void main(String[] args) {
- Random randomNumber = new Random();
- //
- int a;
- int b;
- int c;
- int d;
- int e;
- int attempts = 10;
- Scanner input = new Scanner(System.in);
- System.out.println("Guess five(5) numbers from 1 - 20: ");
- //Creating a loop for the game
- for(int counter =1; counter <= 100; counter++){
- /*User's numbers are placed*/
- int numA = input.nextInt();
- int numB = input.nextInt();
- int numC = input.nextInt();
- int numD = input.nextInt();
- int numE = input.nextInt();
- /*this will show the right number and the number you input*/
- a = 1+randomNumber.nextInt(20);
- System.out.println("right number: "+a+" Your answer: "+ numA);
- b = 1+randomNumber.nextInt(20);
- System.out.println("right number: "+b+" Your answer: "+ numB);
- c = 1+randomNumber.nextInt(20);
- System.out.println("right number: "+c+" Your answer: "+ numC);
- d = 1+randomNumber.nextInt(20);
- System.out.println("right number: "+d+" Your answer: "+ numD);
- e = 1+randomNumber.nextInt(20);
- System.out.println("right number: "+e+" Your answer: "+ numE);
- //the logic part of the program
- if(a == numA && b == numB && c == numC && d == numD && e == numE ){
- System.out.println("Excellent!!!");
- }else if((a==numA && b==numB) || (a==numA && c==numC) || (a==numA &&d==numD) || (a==numA &&e==numE) || (b==numB &&c== numE) || (b==numB &&d==numD) || (b==numB &&e==numE) || (c==numC &&d==numD )|| (d==numD && e==numE)){
- System.out.println("Good!!!");
- /*Game closes here if game is won*/
- System.exit(0);
- }else{
- System.out.println("You lose!!!");
- System.out.println("\n\nTry Again...");
- attempts--;/*this will reduce if player keeps losing*/
- System.out.println("Attempts remaining: "+attempts);
- //loop repeats
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement