Advertisement
galinyotsev123

ProgBasics05while-Loop-Y02oldBooks

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