Plz check output screenshot Write a program that prints the
Plz check output& screenshot
Write a program that prints the following table using the System.out.printf() method. Use the following string for the format for the 1^st line: \"%-15s%15s%15s%15s%n\" Use the following string for the format for the 2^nd and 3^rd lines: \"%-15s%15.2f%15d%15.2f%n\"Solution
Hi , please find the program and it\'s output.
=====PRG======
public class StringFormattor {
public static void main(String args[])
{
System.out.printf(\"%-15s%15s%15s%15s%n\",\"Item\",\"Unit Price\",\"Quantity\",\"Total Price\");
printItem(\"Laptop\",345.00f,10);
printItem(\"Printer\",113.00f,2);
}
static void printItem(String itemName,float unitPrice,int quantity){
System.out.printf(\"%-15s%15.2f%15d%15.2f%n\",itemName,unitPrice,quantity,(unitPrice*quantity));
}
}
====O/P=====
Item Unit Price Quantity Total Price
Laptop 345.00 10 3450.00
Printer 113.00 2 226.00
Let me know if you have any doubts.
