Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _05_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 booksCount = 0;
- String book = scanner.nextLine();
- while (!book.equals(annysBook)) {
- if (book.equals("No More Books")) {
- break;
- }
- booksCount++;
- book = scanner.nextLine();
- }
- if (book.equals(annysBook)) {
- System.out.printf("You checked %d books and found it.", booksCount);
- } else {
- System.out.printf("The book you search is not here!%n" +
- "You checked %d books.", booksCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement