/**
* Its a guessing game.
*
* @author Charlie
* @version 1
*/
import java.util.*;
import java.util.Scanner;
public class guessingGame3
{
public static void main(String args[]){
boolean playing = true;
while(playing){
int counter = 0;
int max = 10;
int min = 1;
int randomNum = (int)(Math.random() * ((max - min) + 1)) + min;
Scanner scan = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to Guessing Game!");
while(counter<=3){
System.out.println("Enter a number between 1 and 10");
int guessInt = scan.nextInt();
if(guessInt == randomNum){
System.out.println("Congrats You Won!");
System.out.println("Press 1 to play again and 2 to cancel");
int again = sc.nextInt();
if(again == 1){
counter = 4;
}
if(again == 2 ){
playing = false;
counter = 4;
}
}
if(guessInt != randomNum){
counter ++;
if(counter>2){
System.out.println("You lost");
System.out.println("Press 1 to play again and 2 to cancel");
int again = sc.nextInt();
if(again == 1){
counter = 4;
}
if(again == 2 ){
playing = false;
counter = 4;
}
}else{
System.out.println("Try Again!");
}
}
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.