Advertisement
Guest User

1

a guest
May 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OldBooks {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String bookName = scanner.nextLine();
  7. int booksNum = Integer.parseInt(scanner.nextLine());
  8. int booksChecked = 0;
  9. boolean isFound = false;
  10. String currentBook = "";
  11.  
  12. while (!isFound && booksChecked<booksNum) {
  13. currentBook = scanner.nextLine();
  14. if (bookName.equals(currentBook))
  15. isFound = true;
  16. else
  17. booksChecked++;
  18. }
  19. if (isFound)
  20. System.out.printf("You checked %d books and found it.",booksChecked);
  21. else
  22. System.out.printf("The book you search is not here!\n" +
  23. "You checked %d books.",booksChecked);
  24.  
  25.  
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement