Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package graod1do10;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10. import static java.lang.Math.abs;
  11.  
  12. /**
  13. *
  14. * @author Mateu
  15. */
  16. public class GraOd1Do10 {
  17.  
  18. /**
  19. * @param args the command line arguments
  20. */
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23.  
  24. System.out.print("Witaj w grze zgadnij liczbę od 1-10");
  25. Scanner sc =new Scanner(System.in);
  26.  
  27. System.out.print("czy chcesz zagrac? (y=yes,n=no)");
  28. String condition=sc.nextLine();
  29. Random random = new Random();
  30. int randomNum;
  31. while(condition.equals("y"))
  32. {
  33. randomNum=abs((random.nextInt())%11);
  34. System.out.print("zgadnij liczbę od 1-10");
  35. int numberFromUser;
  36. numberFromUser=sc.nextInt();
  37. while(numberFromUser!=randomNum)
  38. {
  39. if(randomNum>numberFromUser)
  40. {
  41. System.out.print("za mało");
  42. }
  43. else
  44. {
  45. System.out.print("za duzo");
  46. }
  47. // System.out.print("liczba:"+ randomNum+"\n");
  48.  
  49. System.out.print("Podaj kolejną liczbę:");
  50. numberFromUser=sc.nextInt();
  51. }
  52. System.out.print("Zgadłeś liczbe:"+ randomNum+"\n");
  53. System.out.println("czy chcesz ponowine zagrać ?(y=yes,n=no)");
  54. condition=sc.nextLine();
  55. condition=sc.nextLine();///dlaczego to tak działą ??? ?
  56. }
  57. System.out.print("Dziękuje za grę");
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement