8.运算符_算术运算符_字符串连接
This commit is contained in:
20
day02/src/com/inmind/Demo07.java
Normal file
20
day02/src/com/inmind/Demo07.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.inmind;
|
||||
/*
|
||||
8.运算符_算术运算符_字符串连接
|
||||
+ 符号在遇到字符串的时候,表示连接、拼接的含义,得到一个更长的字符串
|
||||
*/
|
||||
public class Demo07 {
|
||||
public static void main(String[] args) {
|
||||
//定义了一个字符串
|
||||
String str = "abc";
|
||||
//定义了一个字符串
|
||||
String str1 = "123";
|
||||
System.out.println(str+str1);//abc123
|
||||
|
||||
//数字与字符串进行加法运算
|
||||
System.out.println("abc"+123);//abc123
|
||||
System.out.println(123+"abc"+123);//123abc123
|
||||
System.out.println(1+2+"abc");//3abc
|
||||
System.out.println(1+2+"abc"+1+2);//12abc12
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user