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