Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package O5_Loops.Exercise;
- import java.util.Scanner;
- public class Ex02OldBooks {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String searchBook = scanner.nextLine();
- int capacity = Integer.parseInt(scanner.nextLine());
- int searches = 0;
- while (searches < capacity) {
- String randomBooks = scanner.nextLine();
- searches++;
- if (randomBooks.equalsIgnoreCase(searchBook)) {
- --searches;
- break;
- }
- }
- if (searches >= capacity) {
- System.out.println("The book you search is not here!");
- System.out.printf("You checked %d books.", searches);
- } else {
- System.out.printf("You checked %d books and found it.", searches);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement