Java 打印商品价格清单和结算清单,输入三个商品名称和数量,求出商品价格总额,再将商品打8折,计算机折后价,并将商品清单和结算清单打印输出
时间: 2024-05-25 07:18:07 浏览: 12
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] names = new String[3];
int[] counts = new int[3];
double[] prices = new double[3];
double total = 0.0;
for (int i = 0; i < 3; i++) {
System.out.print("请输入第" + (i + 1) + "个商品的名称:");
names[i] = input.next();
System.out.print("请输入第" + (i + 1) + "个商品的数量:");
counts[i] = input.nextInt();
System.out.print("请输入第" + (i + 1) + "个商品的价格:");
prices[i] = input.nextDouble();
total += counts[i] * prices[i];
}
double discount = total * 0.2;
double payable = total - discount;
System.out.println("商品价格清单:");
System.out.println("---------------------");
System.out.println("名称\t数量\t价格");
for (int i = 0; i < 3; i++) {
System.out.println(names[i] + "\t" + counts[i] + "\t" + prices[i]);
}
System.out.println("---------------------");
System.out.println("总价:" + total);
System.out.println("折扣:" + discount);
System.out.println("应付:" + payable);
System.out.println("结算清单:");
System.out.println("---------------------");
System.out.println("名称\t数量\t折后价");
for (int i = 0; i < 3; i++) {
double discountedPrice = prices[i] * 0.8;
System.out.println(names[i] + "\t" + counts[i] + "\t" + discountedPrice);
}
System.out.println("---------------------");
System.out.println("总价:" + total);
System.out.println("折扣:" + discount);
System.out.println("应付:" + payable);
}
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)