Hint
Read the data with nextLine(), and convert the year with Integer.parseInt (this way you avoid the problem with the rest of the line after nextInt()). Collect the books you find into a new list and sort it with Comparator.comparingInt(b -> b.year).
Solution (Java)
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
class Book {
String title, author;
int year;
Book(String title, String author, int year) {
this.title = title;
this.author = author;
this.year = year;
}
}
public class Library {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine().trim());
ArrayList<Book> books = new ArrayList<>();
for (int i = 0; i < n; i++) {
String title = sc.nextLine();
String author = sc.nextLine();
int year = Integer.parseInt(sc.nextLine().trim());
books.add(new Book(title, author, year));
}
String wanted = sc.nextLine();
ArrayList<Book> found = new ArrayList<>();
for (Book b : books) {
if (b.author.equalsIgnoreCase(wanted)) found.add(b);
}
found.sort(Comparator.comparingInt(b -> b.year)); // by year, ascending
if (found.isEmpty()) System.out.println("No books");
for (Book b : found) System.out.println(b.year + " " + b.title);
}
}