040_字符串连接符

package test_package;

/**
* 字符串运算符
* @author
*
*/
public class TestOperator05 {
public static void main(String[] args) {
String a = "3";
int b = 4;
int c = 5;
char d = 'a';
System.out.println(a+b+c);//因为3是字符串,后面都是字符串连接
System.out.println(b+c+a);//9+a,a是字符串
System.out.println(d+4); //97+4=101,d在ASCLL码中是97
}
}

041_条件运算符目

/**
* 条件运算符(三元运算符)
* @author
*
*/
public class TestOperator06 {
public static void main(String[] args) {
int score = 80;
int x = -100;
String type = score<60?"不及格":"及格";
System.out.println(type);

if(score<60){
System.out.println("不及格");
}else{
System.out.println("及格");
}

System.out.println(x > 0 ? 1 : (x == 0 ? 0 : -1));

}
}

心得:三元运算符可以用if条件分支语句替代

 042_运算符优先级_逻辑与或优先问题

心得:

1、尽量使用小括号来区分优先级。

2、逻辑运算符优先级:非>与>或

非的运算优先级在逻辑运算符内最高,最低的是或

例:a||b&&c  的正确顺序是 a||(b&&c)

043_自动类型转化

package test_package;

/**
* 测试自动类型转化
* @author
*
*/
public class TestTypeConvert {
public static void main(String[] args) {
int a = 324;
long b = a;
double d = b;
// a = b; //不合法Type mismatch: cannot convert from long to int
// long e = 3.23F;
float f = 234324L;
short y=12345;//6位short类型就溢出了
//特例
byte b2 = 123;

}
}

心得:

1、容量小的数据类型可以向容量大的数据类型的变量自动转化。

044_强制类型转换

在需要强制转化的数据类型前加小括号(),在括号内填入需要转为的目标数据类型。

心得:

强行转化的过程中要注意精度丢失的问题。

045_基本类型常见错误_溢出_L问题

/**
* 测试类型转换常见问题
* @author
*
*/
public class TestTypeConvertError {
public static void main(String[] args) {
int money = 1000000000; //10亿
int years = 20;
//返回的total是负数,超过了int的范围
int total = money*years;
System.out.println("total="+total);
//返回的total仍然是负数。默认是int,因此结果会转成int值,再转成long。但是已经发生//了数据丢失
long total1 = money*years;
System.out.println("total1="+total1);

//返回的total2正确:先将一个因子变成long,整个表达式发生提升。全部用long来计算。
long total2 = money*((long)years);
System.out.println("total2="+total2);

long total3 = 34L*3223*years*223423;//将第一个数数转位long,这样后续的计算就都是long了

System.out.println(total3);
//命名问题
int l = 2; //分不清是L还是1,
long a = 23451l;//建议使用大写L
System.out.println(l+1);

}
}

040_字符串连接符 041_条件运算符目 042_运算符优先级_逻辑与或优先问题 043_自动类型转化 044_强制类型转换 045_基本类型常见错误_溢出_L问题的更多相关文章

  1. Java学习笔记四:三目运算符与字符串连接符等

    一 .三目运算符与自增自减 GitHub代码练习地址:https://github.com/Neo-ML/JavaPractice/blob/master/OperPrac02.java 条件运算符由 ...

  2. JavaSE复习日记 : Java操作符\关系运算符\逻辑运算符\赋值运算符\字符串连接符\三元运算符

    // Java操作符\关系运算符\逻辑运算符\赋值运算符\字符串连接符\三元运算符 /* * 一 Java操作符 * * Java操作符都有哪些? * +, -, *, /, %, ++, -- * ...

  3. php变量和字符串连接符——点

    连接符——点,本身也是一种运算符.它真正的名字应该叫“字符运算符”.作用是把两个字符串连接起来. echo 字符 . 变量 . 字符;  //点号把三个值连接成为一个,运行正常. 例: 1.字符串+变 ...

  4. 6——PHP顺序结构&&字符串连接符

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  5. mysql的字符串连接符

    以前用SQL Server 连接字符串是用“+”,现在数据库用mysql,写个累加两个字段值SQL语句居然不支持"+",郁闷了半天在网上查下,才知道mysql里的+是数字相加的操作 ...

  6. MYSQL中的字符串连接符

    update `table` set nsdf = concat('a','b') where id=137

  7. php const常量 不能使用字符串连接符.链接

    class jdpay extends pay { const BASE_URL = "https://mapi.jdpay.com/npp10/"; private $agree ...

  8. 优化php代码 - 字符串echo输出 逗号也可作php连接符

    2016年12月12日10:00:16 ====================== 网页访问速度的提升,是可以通过代码的优化来实现的.代码的优化,并不是说代码越少越好,而是主要看代码的运行能力和执行 ...

  9. 数据库学习(三) sql语句中添加函数 to_char,round,连接符||

    ** to char 是把日期或数字转换为字符串  to date 是把字符串转换为数据库中得日期类型  参考资料:https://www.cnblogs.com/hllnj2008/p/533296 ...

随机推荐

  1. ubuntu 开启对.htaccess的支持

    1. 终端运行    sudo a2enmod    程序提示可供激活的模块名称,输入:    rewrite    成功会提示 rewrite already load2. 修改/etc/apach ...

  2. 在vue中使用elementUI饿了么框架使用el-tabs,切换Tab如何实现实时加载,以及el-table表格使用总结

    当我们在开发中遇到tab切换,这时候用el的el-tabs感觉很方便 但当我在把代码都写完后,发现一个问题就是页面打开时 虽然我们只能看见当前一个tab页,但是vue会帮你把你写的所有tab页的内容都 ...

  3. Ecshop各个页面文件介绍,主要文件功能说明

    1.模板文件说明 style.css – 模板所使用样式表activity.dwt – 活动列表article.dwt – 文章内容页article_cat.dwt – 文章列表页article_pr ...

  4. 2018-2019 ACM-ICPC, Asia East Continent Final L Eventual … Journey

    #include<iostream> using namespace std; ; int cnt[MAX]; int ans[MAX]; int a[MAX]; int main() { ...

  5. New Skateboard

    Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new ...

  6. dojo - 相关教程

    https://blog.csdn.net/dojotoolkit/article/details/6688058

  7. IntelliJ IDEA 2017.3-----导入jar包

    1.选择jar包 2.右键选择 3.点击ok

  8. C++内存管理(new operator/operator new/operator delete/placement new)

    new operator 我们平时使用的new是new操作符(new operator),就像sizeof一样是语言内置的,不能改变它的含义,功能也是一样的 比如: string *ps = new ...

  9. ignoreContentAdaptWithSize

    使用cocosStudio 中 的Text控件时,要设定text.ignoreContentAdaptWithSize(true); 设定控件(0.5,0.5)锚点位置不随文本长度变化而变化.

  10. DSP---TI CCSv5.5.x-Windows安装

    TI CCSv5.5.x(正式版)-Windows版本 国内2013年9月13日首发安装CCSv5.5图示 *请关掉防火墙及杀毒软件进行安装 第一步 第二步 安装程序检测到挂起的重新启动,这可能在安装 ...