Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S5_WhileLoops;
- import java.util.Scanner;
- public class OldBooks {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String annysBook = scanner.nextLine();
- int booksCheckedCount = 0;
- boolean isBookFound = false;
- String bookName = scanner.nextLine();
- while (!bookName.equals("No More Books")) {
- if (bookName.equals(annysBook)) {
- isBookFound = true;
- break;
- }
- booksCheckedCount++;
- bookName = scanner.nextLine();
- }
- if (isBookFound) {
- System.out.printf("You checked %d books and found it.", booksCheckedCount);
- } else {
- System.out.printf("The book you search is not here!%n" +
- "You checked %d books.", booksCheckedCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement