aneliabogeva

OldBooks

Dec 13th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 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 favoriteBook = scanner.nextLine();
  7.         String book = scanner.nextLine();
  8.         Integer counter = 0;
  9.  
  10.         while (!"No More Books".equals(book)){
  11.             if(!book.equals(favoriteBook)){
  12.                 book = scanner.nextLine();
  13.                 counter +=1;
  14.             }else{
  15.                 System.out.printf("You checked %d books and found it.",counter);
  16.                 break;
  17.             }
  18.         }
  19.         if(!book.equals(favoriteBook)){
  20.             System.out.println("The book you search is not here!");
  21.             System.out.printf("You checked %d books.",counter);
  22.         }else{}
  23.     }
  24. }
  25.  
Add Comment
Please, Sign In to add comment