Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Krisu {
- public static void main (String []args) {
- ArrayList<String> list = new ArrayList<String>();
- Scanner sc = new Scanner(System.in);
- String author;
- String title;
- String publisher;
- String answer;
- int sum = 0;
- System.out.println("Do you want to input a book? (y/n)");
- answer = sc.nextLine();
- while (answer.equals("y")) { //Ywhile
- System.out.println("Please write the author's name: ");
- author = sc.nextLine();
- list.add(author);
- System.out.println("Please write the title: ");
- title = sc.nextLine();
- list.add(title);
- System.out.println("Please write the publisher : ");
- publisher = sc.nextLine();
- list.add(publisher);
- sum++;
- System.out.println("Do you want to enter another book? (y/n)");
- answer = sc.nextLine();
- }// Nwhile
- if (!answer.equals("y")) { //Yif
- System.out.println("Case closed");
- } //Nif
- int size = list.size();
- System.out.println("The library contains: " + sum + " books");
- System.out.println("The arraylist contains the following elements: "+ list);
- }//1
- }//2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement