Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Book longestTitleForEach(Book book) {
- if (nbBook == 0) { //Si nombre de book = 0 alors il n'y a pas de book
- return null;
- }
- Book longuestTitle = books.get(0); //on stock le livre qui a pour l'instant la plus grande taille
- int longuestSize = longuestTitle.getTitle().length();
- books.forEach((i) -> {
- Book currentBook = i;
- int currentSize = currentBook.getTitle().length();
- if (currentSize > longuestSize) {
- longuestTitle = currentBook;
- longuestSize = currentSize;
- }
- });
- return longuestTitle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement