Advertisement
MladenKarachanov

OldBooks

Dec 22nd, 2022
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package firstStepsInCoding;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class OldBooks {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String book = scanner.nextLine();
  9.  
  10.        int count=0;
  11.        boolean isFound=false;
  12.        String input=scanner.nextLine();
  13.         while (!input.equals("No More Books")){
  14.             if (input.equals(book)){
  15.                 isFound=true;
  16.                 break;
  17.             }
  18.             count++;
  19.             input=scanner.nextLine();
  20.         }
  21.         if (isFound){
  22.             System.out.printf("You checked %d books and found it.",count  );
  23.  
  24.         }else{
  25.             System.out.printf("The book you search is not here!%n",count);
  26.             System.out.printf("You checked %d books",count);
  27.         }
  28.  
  29.  
  30.             }
  31.         }
  32.  
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement