Java字符串的输出规则

public class TestVarChar1
{
	public static void main(String[] args)
	{
		char ch1='a'+2;
		System.out.println(ch1+2);//101;
		System.out.println(ch1);//c
		System.out.println(666-ch1);//567
		//在内存中,字符是按照码进行计算、存储的;
		//但是在输入、输出时均为所见即所得;
		//char类型是按照Unicode来储存的;
		
		//ch1=ch1+2;
		//ch1无法直接进行加减计算,只能在声明或输出的时候进行;
		//System.out.println(ch1);
		
		char ch2='中';
		System.out.println(ch2+2);//20015;
		System.out.println(ch2);//中
		System.out.println(666-ch2);//-19347
		//该原则对于中文字符或任何字符都是成立的;
		
		int num1=(int)ch2;
		System.out.println(num1);
		//使用(int)将字符强行转化为数字,输出字符对应的编码;
		
		char ch3=(char)20013;
		System.out.println(ch3);
		//使用(char)将数字强行转化为字符,输出编码对应的字符;
		
		System.out.println("------------------------------");
		int num2=ch2;
		char ch4=20013;
		System.out.println(ch4);
		System.out.println(num2);
		//不使用转化直接赋值也是可以的;
		//输出仍为字符编码对应的字符和字符对应的编码;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值