Advertisement
desislava_topuzakova

01. Old Books начин 1

Jul 5th, 2020
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OldBooks_01 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String searchedBook = scanner.nextLine();
  7.         //1. ако открием книгата   2. ако получим команда "No book...."
  8.  
  9.         String command = scanner.nextLine();
  10.         //команда -> no more books  или заглавие на книга
  11.         int countCheckedBooks = 0;
  12.         while (!command.equals("No More Books")) {
  13.             //команда -> заглавие
  14.             if (command.equals(searchedBook)) {
  15.                 //намираме книгата
  16.                 System.out.printf("You checked %d books and found it.", countCheckedBooks);
  17.                 break;
  18.             } else {
  19.                 countCheckedBooks++;
  20.         }
  21.             command = scanner.nextLine();
  22.         }
  23.  
  24.         if (command.equals("No More Books")){
  25.             System.out.println("The book you search is not here!");
  26.             System.out.printf("You checked %d books.", countCheckedBooks);
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement