veronikaaa86

01. Old Books

Feb 6th, 2022
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P01OldBooks {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String wantedBook = scanner.nextLine();
  10.  
  11. int countBooks = 0;
  12. boolean wasFound = false;
  13. String command = scanner.nextLine();
  14. while (!command.equals("No More Books")) {
  15. String currentBook = command;
  16.  
  17. if (currentBook.equals(wantedBook)) {
  18. wasFound = true;
  19. break;
  20. }
  21.  
  22. countBooks++;
  23.  
  24. command = scanner.nextLine();
  25. }
  26.  
  27. if (wasFound) {
  28. System.out.printf("You checked %d books and found it.", countBooks);
  29. } else {
  30. System.out.printf("The book you search is not here!%nYou checked %d books.",
  31. countBooks);
  32. }
  33.  
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment