java 中+的运算规则


1.Java中的加法的运算优先级是从左往右的

2.字符串""隔壁跟的+号意思是字符串的连接 就不是加法了

3.'字符' 后面的+号意思是'字符'的ascall码值和后面的值相加

class DataTypeDemo9 {
	public static void main(String[] args){
		System.out.println("hellow"+'a'+'1');   // 输出helloa1
		System.out.println('a'+1+"hello");       // 输出为98hellow  ('a'='A'+'0'  ,97 = 65 + 32  )(97+1 再连接hellow 字符串)
		System.out.println("5+5="+5+5);        // 输出为字符串5+5=55(字符串的连接)
		System.out.println(5+5+"=5+5");        // 输出为10=5+5  (先算出5+5的运算 得出10再连接字符串"5+5")
		
		
	}
}  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM