Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. //Maya Gambhir 9/5/19 B Block
  2. import java.util.*;
  3. public class GuessingGame
  4. {
  5. public static void main (String[]args){
  6. Scanner sc=new Scanner (System.in);
  7. int again;
  8. do{
  9. boolean x=false;
  10. double random = (int)(Math.random() * (10) + 1);
  11. do{
  12. System.out.println("Enter a number");
  13. int guess=sc.nextInt();
  14. while (guess>10 || guess<1){
  15. System.out.print("Not a valid guess try again");
  16. guess=sc.nextInt();
  17. }
  18. if (!(guess==random)){
  19. System.out.println("Incorrect try again");
  20. }
  21. else {x = true;}
  22. }while(!x);
  23. System.out.println("Winner!");
  24. System.out.println("Enter 1 to play again or 0 to quit");
  25. again=sc.nextInt();
  26. }while (again==1);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement