Java基础+数据库.doc

  1. 1、本文档共102页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java基础+数据库.doc

一、8种数据类型与逻辑运算 (1)Java有8种数据类型public static void main(String[] args) { //数据类型的有4种 //字节类型 byte b = 2;// (8位) System.out.println(字节型 +b); //短整型 short s = 20;// (16位) System.out.println(短整型 +s); //整型 int i = 200;// (32位) System.out.println(整型: +i); //长整型 long g = 2000;// (64位) System.out.println(长整型: +g); // 浮点类型的有2个; // 以下2种类型的相同点都是存储浮点数,不同点存储范围由小到大 // 默认使用双精度浮点数 // 单精度浮点数,注意:数字后面一定要加F或f,表示该数字是float类型,因为浮点数默认是double类型 float f = 1.2F;// (32位) System.out.println(单精度: +f); // 双精度浮点数 double d = 1.23;// (64位) System.out.println(双精度: +d); // 2个特殊数据类型 // 布尔类型 boolean boo = true;//真 boo = false;//假 System.out.println(布尔类型: + boo); // 字符类型,注意:单个字符 char c = 你;// (16位) System.out.println(字符类型: + c);} (2)Java的比较运算符与逻辑运算符 public static void main(String[] args) { // 赋值运算符 int x = 10; int y = 20; int z = 30; int sum = x + y + z; System.out.println(sum);60 int a = 2; a += 3;//a = a + 3; System.out.println(a); //结果:5 //练习 int b = 10; short s = 20; //注意:类型不一致,首先低精度向高精度转,然后计算 //s = s + b; s += b;//自动转换类型 System.out.println(s); //(2)比较运算符:最终结果一定是布尔类型(true/false) System.out.println(3 2); System.out.println(3 = 2); //结果:true System.out.println(3 2); //结果:false System.out.println(3 = 2); //结果:false System.out.println(3 == 2); //结果:false System.out.println(3 != 2); //结果:true // (3)三目操作符 int c = (3 2) ? 3 : 2; System.out.println(c); // (4)算数运算符 System.out.println(3 + 2); System.out.println(2 - 3); //结果:-1 System.out.println(2 * 3); //结果:6 System.out.println(2 / 3); //结果:0 System.out.println(2 % 3); //结果:2 // (5)自增自减 // ++在前,先自增,在参与运算 在后,先参与运算,在自减 int e = 2; System.out.println(++e); int f = 3; System.out.println(f--); //结果:3 // (6)逻辑运算符 // 非运算符 System.out.println(!true); // 逻辑与:都为true,结果为true,其余都是false

文档评论(0)

xinshengwencai + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:5311233133000002

1亿VIP精品文档

相关文档