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