字符和字符串参与加法运算

字符参与加法运算,实际上是拿字符在计算机中存储的数据值来参与计算的
‘A’ = 65
‘a’ = 97
‘0’ = 48

字符串参与加法运算,其实做的不是加法运算,而是字符串的拼接

package com.it;

public class Operator1 { 
       public static void main(String[] args) {
       	 //定义变量
  	 int a = 10;
 	 int b = 20;

  	 System.out.println(a + b);
  	 System.out.println("----------------");
  
 	 //字符参与加法运算
 	 char c = 'A';
 	 System.out.println(a + c);
 	 System.out.println("----------------");
  
  	//字符串参与加法运算
 	 System.out.println("hello" + a);
  	System.out.println("hello" + a + b);
  	System.out.println(a + b + "helloworld");
	 }
}

在这里插入图片描述


版权声明:本文为qq_41799736原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。