silviasj

Old Books3

May 4th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Task4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // name of the book and number of books in the library
  14.             string bookName = Console.ReadLine();
  15.             int allBooks = int.Parse(Console.ReadLine());
  16.             int searches = 0;
  17.             bool bookFound = false;
  18.             // main loop for searching the book
  19.             for (int i = 0; i < allBooks; i++)
  20.             {
  21.                string foundit = Console.ReadLine();
  22.                 if (bookName == foundit)
  23.                 {
  24.                     bookFound = true;
  25.                     break;
  26.                 }
  27.                 searches++;
  28.             }
  29.  
  30.             // output the result
  31.             if (bookFound)
  32.             {
  33.                 Console.WriteLine($"You checked {searches} books and found it.");
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("The book you search is not here!");
  38.                 Console.WriteLine($"You checked {searches} books.");
  39.             }
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment