Advertisement
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 inputLine = scanner.nextLine();
- while (!inputLine.equals("No More Books")) {
- String currentBook = inputLine;
- if (currentBook.equals(wantedBook)) {
- wasFound = true;
- break;
- }
- countBooks++;
- inputLine = scanner.nextLine();
- }
- if (wasFound) {
- System.out.printf("You checked %d books and found it.", countBooks);
- } else {
- System.out.println("The book you search is not here!");
- System.out.printf("You checked %d books.", countBooks);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement