Advertisement
Kancho

Library

Feb 5th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Scanner keyboard = new Scanner(System.in);
  2. System.out.print("Book title: ");
  3. String title = keyboard.nextLine();
  4. System.out.print("Number of books: ");
  5. int bookNum = Integer.parseInt(keyboard.nextLine());
  6. int checkedBooks = 0;
  7. String currentBook = "";
  8. while (bookNum > 0) {
  9. currentBook = keyboard.nextLine();
  10. if (currentBook.equalsIgnoreCase(title)) {
  11. System.out.printf("You found %s after you checked %d books.", title, Math.abs(checkedBooks));
  12. break;
  13. } else {
  14. // bookNum--;
  15. checkedBooks--;
  16. }
  17. if (bookNum == 0) {
  18. System.out.printf("You checked %d books but you did not find %s.",Math.abs(checkedBooks),title);
  19. }
  20. }
  21.  
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement