Advertisement
SophiYo

Ex02OldBooks[ProgrammingBasic]

Nov 29th, 2018
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package O5_Loops.Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex02OldBooks {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String searchBook = scanner.nextLine();
  9.         int capacity = Integer.parseInt(scanner.nextLine());
  10.         int searches = 0;
  11.  
  12.         while (searches < capacity) {
  13.             String randomBooks = scanner.nextLine();
  14.             searches++;
  15.  
  16.             if (randomBooks.equalsIgnoreCase(searchBook)) {
  17.                 --searches;
  18.                 break;
  19.             }
  20.         }
  21.  
  22.         if (searches >= capacity) {
  23.             System.out.println("The book you search is not here!");
  24.             System.out.printf("You checked %d books.", searches);
  25.         } else {
  26.             System.out.printf("You checked %d books and found it.", searches);
  27.         }
  28.  
  29.  
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement