Advertisement
Spocoman

Old Books

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