Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OutputTable {
  4. public static void main() {
  5.  
  6. float[] prices = { 9.92, 6.32, 12.63, 5.95, 10.29 };
  7. float[] units = new float[5], amounts = new float[5];
  8. int total;
  9.  
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. for(int i = 0; i < 5; i++) {
  13. System.out.println("Enter the units for item " + (i + 1));
  14. units[i] = scan.nextFloat();
  15. amounts[i] = prices[i] * units[i];
  16. total += amounts[i];
  17. }
  18.  
  19. System.out.format("%10s%10s%10s", "Price", "Unit", "Amount");
  20. System.out.format("%10s%10s%10s", "-------", "-------", "----------");
  21.  
  22. for(int i = 0; i < 5; i++) {
  23. System.out.format("%10s %10d %10s %n", "$" + String.format("%.2f",prices[i]), units[i], "$" + String.format("%.2f",amounts[i]));
  24. }
  25.  
  26. System.out.format("%10s %10s %10s", "-------", "-------", "----------");
  27. System.out.format("%10s %10s %10s", "Total:", "", "$" + String.format("%.2f",total));
  28. }
  29. }
Add Comment
Please, Sign In to add comment