Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OutputTable {
- public static void main() {
- float[] prices = { 9.92, 6.32, 12.63, 5.95, 10.29 };
- float[] units = new float[5], amounts = new float[5];
- int total;
- Scanner scan = new Scanner(System.in);
- for(int i = 0; i < 5; i++) {
- System.out.println("Enter the units for item " + (i + 1));
- units[i] = scan.nextFloat();
- amounts[i] = prices[i] * units[i];
- total += amounts[i];
- }
- System.out.format("%10s%10s%10s", "Price", "Unit", "Amount");
- System.out.format("%10s%10s%10s", "-------", "-------", "----------");
- for(int i = 0; i < 5; i++) {
- System.out.format("%10s %10d %10s %n", "$" + String.format("%.2f",prices[i]), units[i], "$" + String.format("%.2f",amounts[i]));
- }
- System.out.format("%10s %10s %10s", "-------", "-------", "----------");
- System.out.format("%10s %10s %10s", "Total:", "", "$" + String.format("%.2f",total));
- }
- }
Add Comment
Please, Sign In to add comment