JAVA學習day02

1、基本數據類型
四類八種

2、變量定義後,不賦值,不能使用,即必須進行賦值後才能使用;

3、自增和自減
++a 和a++相等
但是在計算時,有如下差別
a=3
b=a++
b=3,a=4


a=3
c=++a
c=4,a=4

4、賦值

5、打印清單
實現商品庫存清單案例
步驟:
1、實現表頭,是固定數據,直接寫輸出語句;
2、表格中間,商品數據,採用變量形式,定義變量,找對數據類型,輸出所有變量
3、表格尾巴,一部分數據固定
另一部分:商品數據進行數學計算
*/

public class Shop {

public static void main(String[] args) {
    //輸出表頭固定數據
    System.out.println("---------商品庫存清單-----------");
    System.out.println("品牌型號         尺寸       價格        庫存數");
    //定義表格中的數據變量
    //品牌型號String    尺寸,價格double    庫存int
    String macBrand="MacBookAir";
    double macSize=13.3;
    double macPrice=6898.88;
    int macCount=5;

    String thinkBrand="ThinkPadT450";
    double thinkSize=14;
    double thinkPrice=5999.88;
    int thinkCount=10;

    String asusBrand="ASUS-FL5800";
    double asusSize=15.6;
    double asusPrice=4999.5;
    int asusCount=18;
    System.out.println(macBrand+"      "+macSize+"     "+macPrice+"      "+macCount);
    System.out.println(thinkBrand+"    "+thinkSize+"     "+thinkPrice+"      "+thinkCount);
    System.out.println(asusBrand+"     "+asusSize+"     "+asusPrice+"       "+asusCount);

    //計算庫存總數,所有商品數量庫存求和
    int totalCount=macCount+thinkCount+asusCount;
    //計算所有商品的總金額,每個商品價格*庫存數
    double totalMoney=macCount*macPrice+thinkCount*thinkPrice+asusCount*asusPrice;
    System.out.println("總庫存數:"+totalCount);
    System.out.println("所有商品的總金額:"+totalMoney);
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章