Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Book title: ");
- String title = keyboard.nextLine();
- System.out.print("Number of books: ");
- int bookNum = Integer.parseInt(keyboard.nextLine());
- int checkedBooks = 0;
- String currentBook = "";
- while (bookNum > 0) {
- currentBook = keyboard.nextLine();
- if (currentBook.equalsIgnoreCase(title)) {
- System.out.printf("You found %s after you checked %d books.", title, Math.abs(checkedBooks));
- break;
- } else {
- // bookNum--;
- checkedBooks--;
- }
- if (bookNum == 0) {
- System.out.printf("You checked %d books but you did not find %s.",Math.abs(checkedBooks),title);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement