Advertisement
GabrielHr00

01. Old Books

Apr 7th, 2024
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package _05_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 booksCount = 0;
  10.  
  11.         String book = scanner.nextLine();
  12.         while (!book.equals(annysBook)) {
  13.             if (book.equals("No More Books")) {
  14.                 break;
  15.             }
  16.  
  17.             booksCount++;
  18.             book = scanner.nextLine();
  19.         }
  20.  
  21.         if (book.equals(annysBook)) {
  22.             System.out.printf("You checked %d books and found it.", booksCount);
  23.         } else {
  24.             System.out.printf("The book you search is not here!%n" +
  25.                     "You checked %d books.", booksCount);
  26.         }
  27.  
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement