一、这里主要承接案例一的实例,主要运用点是用“\t”代替自行敲出的空格间隔,和运用变量来自动的解除金额结果下面我来贴出代码
第一种:
1.引用"\t"代码:
1 public class SuperMarket {
2 public static void main(String[] args) {
3 System.out.println("\t\t人人乐白金假日购物广场(RenRenLe)\t\t");
4 System.out.println("店\t号:S131\t\t机号:P026\t\t流水号:244");
5 System.out.println("收银员:0312\t\t\t\t\t日期:2014.12.14");
6 System.out.println("=============================================");
7 System.out.println("\t商品名\t\t数量\t\t单价\t\t金额");
8 System.out.println("1\t小肥羊火锅汤料(清汤)110g");
9 System.out.println("6935953399984\t\t1\t\t15.80\t\t15.80");
10 System.out.println("\t\t\t特价商品");
11 System.out.println("2\t海底捞清汤火锅汤料110g");
12 System.out.println("6942032700753\t\t1\t\t17.90\t\t17.90");
13 System.out.println("3\t青岛啤酒瓶装600ml");
14 System.out.println("6923740100059\t\t1\t\t4.50\t\t4.50");
15 System.out.println("4\t青岛啤酒瓶装600ml");
16 System.out.println("6923740100059\t\t1\t\t4.50\t\t4.50");
17 System.out.println("5\t青岛啤酒瓶装600ml");
18 System.out.println("6923740100059\t\t1\t\t4.50\t\t4.50");
19 System.out.println("合计:\t\t\t\t\t\t\t\t\t47.20");
20 }
21 }
2.运行结果:
第二种
1.运用变量:
1 public class SuperMarketRenRenle {
2 public static void main(String[] args) {
3 System.out.println("\t\t人人乐白金假日购物广场(RenRenLe)\t\t");
4 System.out.println("店\t号:S131\t\t机号:P026\t\t流水号:244");
5 System.out.println("收银员:0312\t\t\t\t\t日期:2014.12.14");
6 System.out.println("=============================================");
7 System.out.println("\t商品名\t\t数量\t\t单价\t\t金额");
8 System.out.println("1\t小肥羊火锅汤料(清汤)110g");
9 int n = 1; //代表的是整数
10 float f1 = 15.80f; //代表的是小数
11 float f2 = 17.90f; //代表的是小数
12 float f3 = 4.50f; //代表的是小数
13 System.out.println("6935953399984\t\t"+n+"\t\t"+f1+"\t\t"+(n*f1)+"");
14 System.out.println("\t\t\t特价商品");
15 System.out.println("2\t海底捞清汤火锅汤料110g");
16 System.out.println("6942032700753\t\t"+n+"\t\t"+f2+"\t\t"+(n*f2)+"");
17 System.out.println("3\t青岛啤酒瓶装600ml");
18 System.out.println("6923740100059\t\t"+n+"\t\t"+f3+"\t\t\t"+(n*f3)+"");
19 System.out.println("4\t青岛啤酒瓶装600ml");
20 System.out.println("6923740100059\t\t"+n+"\t\t"+f3+"\t\t\t"+(n*f3)+"");
21 System.out.println("5\t青岛啤酒瓶装600ml");
22 System.out.println("6923740100059\t\t"+n+"\t\t"+f3+"\t\t\t"+(n*f3)+"");
23 float total = (n*f1)+(n*f2)+(n*f3)+(n*f3)+(n*f3);
24 System.out.println("\t合计:\t\t\t\t\t\t\t\t"+total+"");
25 }
26 }
2.运行结果: