Advertisement
Spocoman

01. Old Books

Aug 29th, 2024
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OldBooks {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String book = scanner.nextLine();
  7.         int counter = 0;
  8.  
  9.         String input;
  10.         while (!(input = scanner.nextLine()).equals("No More Books")
  11.                 && !input.equals(book)) {
  12.             counter++;
  13.         }
  14.  
  15.         if (input.equals(book)) {
  16.             System.out.printf("You checked %d books and found it.\n", counter);
  17.         } else {
  18.             System.out.println("The book you search is not here!");
  19.             System.out.printf("You checked %d books.\n", counter);
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement