Advertisement
CoineTre

Ex.1.Old Library Books

Nov 11th, 2020
47
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 bookTitle = scanner.nextLine();
  7.         int booksN = 0;
  8.         String bookCounter = scanner.nextLine();
  9.         boolean isFound = false;
  10.         while(!bookCounter.equals("No More Books")){
  11.             if(bookCounter.equals(bookTitle)){
  12.                 isFound=true;
  13.                 break;
  14.             }
  15.            bookCounter = scanner.nextLine();
  16.             booksN++;
  17.         }
  18.         if (isFound){
  19.             System.out.printf("You checked %d books and found it.",booksN);
  20.         }else{
  21.             System.out.printf("The book you search is not here!%nYou checked %d books.",booksN);
  22.         }
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement