silviasj

Old Books2

May 4th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 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.         int countBooks = Integer.parseInt(scanner.nextLine());
  8.         int countCheckedBooks = 0;
  9.         boolean isFound = false; //false - не сме я открили, true -> открили сме я
  10.         //Стоп -> ако намерим книгата
  11.         //Стоп -> ако броя на книгите == 0
  12.  
  13.         while (countBooks > 0){
  14.             String title = scanner.nextLine();
  15.             countBooks--;
  16.             if(title.equals(searchedBook)){
  17.                 isFound = true;
  18.                 System.out.printf("You checked %d books and found it.", countCheckedBooks);
  19.                 break;
  20.             } else {
  21.  
  22.                 countCheckedBooks++;
  23.             }
  24.  
  25.         }
  26.  
  27.         if(isFound == false){
  28.             System.out.println("The book you search is not here!");
  29.             System.out.printf("You checked %d books.", countCheckedBooks);
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment