Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Book books[] = new Book[5];
  6.  
  7.         books[0] = new Book();
  8.         books[0].title = "Женщина в белом";
  9.         books[0].author = "Уилки Коллинз";
  10.         books[0].publishYear = 1860;
  11.  
  12.         books[1] = new Book();
  13.         books[1].title = "Цветок орхидеи";
  14.         books[1].author = "Джеймс Хедли Чейз";
  15.         books[1].publishYear = 1948;
  16.  
  17.         books[2] = new Book();
  18.         books[2].title = "Брида";
  19.         books[2].author = "Пауло Коэльо";
  20.         books[2].publishYear = 1990;
  21.  
  22.         books[3] = new Book();
  23.         books[3].title = "Милый друг";
  24.         books[3].author = "Ги де Мопассан";
  25.         books[3].publishYear = 1885;
  26.  
  27.         books[4] = new Book();
  28.         books[4].title = "Королёк — птичка певчая";
  29.         books[4].author = "Решат Нури Гюнтекин";
  30.         books[4].publishYear = 1922;
  31.  
  32.         int min = 0;
  33.         int number = 0;
  34.  
  35.         for (int i = 0; i < books.length; i++) {
  36.             if (min > books[i].publishYear) {
  37.                 min = books[i].publishYear;
  38.                 number = i;
  39.             }
  40.         }
  41.         System.out.println("Автор самой старой книги: " + books[number].author + "(" + books[number].publishYear + ")");
  42.  
  43.         Scanner in = new Scanner(System.in);
  44.         System.out.println("Введите автора: ");
  45.         String nameauthor = in.nextLine();
  46.         for (int i = 0; i < books.length; i++) {
  47.             if (books[i].author.equals(nameauthor)==true){
  48.                 System.out.println(books[i].title);
  49.             }
  50.         }
  51.         System.out.println("Введите год издания книги: ");
  52.         int year = Integer.valueOf(in.nextLine());
  53.         for (int i = 0; i < books.length; i++) {
  54.             if (books[i].publishYear < year) {
  55.                 System.out.println(String.format("Название книги: %s; Автор книги: %s; Год издания: %d", books[i].title, books[i].author,books[i].publishYear));
  56.             }
  57.  
  58.         }
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement