fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. // WhileTasks
  5.  
  6. public static void main (String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. String repeat;
  9.  
  10.  
  11. do {
  12. System.out.println("Buy an elephant!");
  13. String userAnswer = scanner.nextLine();
  14. String rightAnswer = "Ok";
  15. int count = 1;
  16.  
  17. while(true) {
  18. if(userAnswer.equals(rightAnswer)) {
  19. if (count > 1) {
  20. System.out.println("Vot tak bi srazu!");
  21. }
  22. System.out.println("Take care, its yours!");
  23. break;
  24. } else {
  25. System.out.println("Everyone says: \"" + userAnswer + "\", but you have to buy an elephant!");
  26. userAnswer = scanner.nextLine();
  27. }
  28. count++;
  29. }
  30.  
  31. System.out.println("\nRepeat task one more time?(yes/no)");
  32. repeat = scanner.nextLine();
  33. } while(repeat.equals("yes"));
  34.  
  35. System.out.println("Good bye!");
  36. scanner.close();
  37.  
  38. }
  39. }
Success #stdin #stdout 0.16s 56612KB
stdin
Ok
no
stdout
Buy an elephant!
Take care, its yours!

Repeat task one more time?(yes/no)
Good bye!