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