SHARE
TWEET

1

a guest May 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 bookName = scanner.nextLine();
  7.             int booksNum = Integer.parseInt(scanner.nextLine());
  8.             int booksChecked = 0;
  9.             boolean isFound = false;
  10.         String currentBook = "";
  11.  
  12.             while (!isFound && booksChecked<booksNum) {
  13.                 currentBook = scanner.nextLine();
  14.                 if (bookName.equals(currentBook))
  15.                     isFound = true;
  16.                 else
  17.                     booksChecked++;
  18.             }
  19.             if (isFound)
  20.                 System.out.printf("You checked %d books and found it.",booksChecked);
  21.             else
  22.                 System.out.printf("The book you search is not here!\n" +
  23.                         "You checked %d books.",booksChecked);
  24.  
  25.  
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top