Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OldBooks_01 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String searchedBook = scanner.nextLine();
- int countBooks = Integer.parseInt(scanner.nextLine());
- int countCheckedBooks = 0;
- boolean isFound = false; //false - не сме я открили, true -> открили сме я
- //Стоп -> ако намерим книгата
- //Стоп -> ако броя на книгите == 0
- while (countBooks > 0){
- String title = scanner.nextLine();
- countBooks--;
- if(title.equals(searchedBook)){
- isFound = true;
- System.out.printf("You checked %d books and found it.", countCheckedBooks);
- break;
- } else {
- countCheckedBooks++;
- }
- }
- if(isFound == false){
- System.out.println("The book you search is not here!");
- System.out.printf("You checked %d books.", countCheckedBooks);
- }
- }
- }
Add Comment
Please, Sign In to add comment