Answer to Question #290221 in Java | JSP | JSF for Hamza

Question #290221

Program Name: MyBookList.java [20]



You are being asked to write a program which will keep the list of books. The program will keep record for



the book’s title, price, and pages. You are required to use the two-dimensional String



array for this purpose.



The array would have n rows and 3 columns where n is the size entered by user. The first, second,



and third columns would be used for storing a book’s title, price and pages respectively. We will also treat



price and pages as a String. This array should be of this form:



Introduction to AI 1200.00 450



Reinforcement Learning 1300.99 1000



Deep Learning: Practical 1575.60 850

1
Expert's answer
2022-01-24T08:48:34-0500
import java.util.*;


public class MyBookList {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.print("Enter the number of books: ");
		int n = keyBoard.nextInt();
		String books[][] = new String[n][3];
		keyBoard.nextLine();
		for (int i = 0; i < n; i++) {
			System.out.print("Enter the inforamtion for book " + (i + 1) + ":\n");
			System.out.print("Enter book's title: ");
			books[i][0] = keyBoard.nextLine();
			System.out.print("Enter book's price: ");
			books[i][1] = keyBoard.nextLine();
			System.out.print("Enter book's pages: ");
			books[i][2] = keyBoard.nextLine();
		}
		System.out.printf("%-20s%-20s%-20s\n", "Title", "Price", "Pages");
		for (int i = 0; i < n; i++) {
			System.out.printf("%-20s%-20s%-20s\n", books[i][0], books[i][1], books[i][2]);
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS