Advertisement
GabrielHr00

01. Old Books

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