Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package graod1do10;
- import java.util.Random;
- import java.util.Scanner;
- import static java.lang.Math.abs;
- /**
- *
- * @author Mateu
- */
- public class GraOd1Do10 {
- /**
- * @param args the command line arguments
- */
- public static void main (String[] args) throws java.lang.Exception
- {
- System.out.print("Witaj w grze zgadnij liczbę od 1-10");
- Scanner sc =new Scanner(System.in);
- System.out.print("czy chcesz zagrac? (y=yes,n=no)");
- String condition=sc.nextLine();
- Random random = new Random();
- int randomNum;
- while(condition.equals("y"))
- {
- randomNum=abs((random.nextInt())%11);
- System.out.print("zgadnij liczbę od 1-10");
- int numberFromUser;
- numberFromUser=sc.nextInt();
- while(numberFromUser!=randomNum)
- {
- if(randomNum>numberFromUser)
- {
- System.out.print("za mało");
- }
- else
- {
- System.out.print("za duzo");
- }
- // System.out.print("liczba:"+ randomNum+"\n");
- System.out.print("Podaj kolejną liczbę:");
- numberFromUser=sc.nextInt();
- }
- System.out.print("Zgadłeś liczbe:"+ randomNum+"\n");
- System.out.println("czy chcesz ponowine zagrać ?(y=yes,n=no)");
- condition=sc.nextLine();
- condition=sc.nextLine();///dlaczego to tak działą ??? ?
- }
- System.out.print("Dziękuje za grę");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement