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