首页 > 编程语言 > 详细

Java引用数据类型字符串

时间:2020-06-27 09:45:14      阅读:61      评论:0      收藏:0      [点我收藏+]

String(字符串):引用数据类型

声明String使用一对双引号

string可以与8中数据类型做运算;且运算只能连接运算运算符+

运算结果也是string类型  ;a = 97

简单示例

class VariableTest1
{
	public static void main(String[] args) 
	{
		String s1 = "chlgg";
		System.out.println("Hello world");
		System.out.println(s1);

	}
}
---------- java ----------
Hello world
chlgg

输出完成 (耗时 0 秒) - 正常终止

  字符串拼接

class VariableTest1
{
	public static void main(String[] args) 
	{
		String s1 = "chlgg";
		System.out.println("Hello world");
		System.out.println(s1);
		int number = 1001;
		String numberStr = "学号";
		String info = numberStr + number;
		System.out.println(info);

	}
}

  测试

class VariableTest1
{
	public static void main(String[] args) 
	{
		char c = ‘a‘;//a等于97
		int num = 10;
		String str = "hello";
		System.out.println (c + num +str);
		System.out.println(c + str + num);
		System.out.println(c+ (num + str));
		System.out.println((str + num +c));

	}
}
---------- java ----------
107hello
ahello10
a10hello
hello10a

输出完成 (耗时 0 秒) - 正常终止

  

Java引用数据类型字符串

原文:https://www.cnblogs.com/rdchenxi/p/13197319.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!