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);
}

}

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