SHARE
TWEET

Old books /// While / if else ***

valentin955 Apr 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Hi {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String wantedBook = scanner.nextLine();
  10.         int capacity = Integer.parseInt(scanner.nextLine());
  11.         int count = 0;
  12.         boolean isBookFounded = true;
  13.  
  14.         String book = scanner.nextLine();
  15.         while (!book.equals(wantedBook)) {
  16.             count++;
  17.  
  18.             if (count == capacity){
  19.                 isBookFounded = false;
  20.                 break;
  21.  
  22.             }
  23.  
  24.             book = scanner.nextLine();
  25.  
  26.  
  27.         }
  28.  
  29.         if (isBookFounded){
  30.             System.out.printf("You checked %d books and found it.",count);
  31.         } else {
  32.             System.out.printf("The book you search is not here!\nYou checked %d books.",count);
  33.         }
  34.  
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top