Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Maya Gambhir 9/5/19 B Block
- import java.util.*;
- public class GuessingGame
- {
- public static void main (String[]args){
- Scanner sc=new Scanner (System.in);
- int again;
- do{
- boolean x=false;
- double random = (int)(Math.random() * (10) + 1);
- do{
- System.out.println("Enter a number");
- int guess=sc.nextInt();
- while (guess>10 || guess<1){
- System.out.print("Not a valid guess try again");
- guess=sc.nextInt();
- }
- if (!(guess==random)){
- System.out.println("Incorrect try again");
- }
- else {x = true;}
- }while(!x);
- System.out.println("Winner!");
- System.out.println("Enter 1 to play again or 0 to quit");
- again=sc.nextInt();
- }while (again==1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement