您现在的位置是:首页 > 文章详情

JAVA学习day02

日期:2019-01-09点击:564

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

}

原文链接:https://yq.aliyun.com/articles/685965
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章