daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class KD5_U7 {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8. Random rand = new Random();
  9. int numberToGuess = rand.nextInt(10);
  10. int numberOfTries = 0;
  11. Scanner dati = new Scanner (System.in);
  12. int guess;
  13. boolean win = false;
  14. while (win == false)
  15. {
  16. System.out.println("Uzmini kādu atzīmi Ēriks ieguva ieskaitē");
  17. guess = dati.nextInt();
  18. numberOfTries++;
  19.  
  20. if (guess == numberToGuess)
  21. {
  22.     win = true;
  23. }
  24. else if(guess < numberToGuess){
  25.     System.out.println("Nepareizi!");
  26.     //2nd thing guess is compared too.
  27. }
  28.  
  29. else if(guess > numberToGuess){
  30.     System.out.println("Nepareizi!");
  31. }
  32. }
  33. System.out.println("Tu uzminēji!");
  34. System.out.println("Ēriks ieskaitē dabūja " + numberToGuess);
  35. System.out.println("Tev vajadzēja "+ numberOfTries + " mēģinājumus.");
  36. dati.close();
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top