案例一1-1:打印超市的購物小票,另外兩種方法

1、這裏主要承接案例一的實例,主要運用點是用「\t」代替自行敲出的空格間隔,和運用變量來自動的解除金額結果下面我來貼出代碼spa

第一種:3d

  1.引用"\t"代碼:code

 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.運行結果:blog

   

第二種class

  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.運行結果:引用

   

相關文章
相關標籤/搜索