JAVA学习day02
1、基本数据类型四类八种 2、变量定义后,不赋值,不能使用,即必须进行赋值后才能使用; 3、自增和自减++a 和a++相等但是在计算时,有如下差别a=3b=a++b=3,a=4 若a=3c=++ac=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); } }