oprationsof string.java
来自「《Java程序设计》第6、7、8章的源代码。有需要者请」· Java 代码 · 共 28 行
JAVA
28 行
public class OprationsOfString{
public static void main(String args[]){
String s1="Hello Java!";
String s2="el";
System.out.println("字符串s1为:"+s1);
System.out.println("字符串s1的长度为:"+s1.length());
System.out.println("字符串s1的大写形式为:"+s1.toUpperCase());
System.out.println("字符串s2的小写形式为:"+s2.toLowerCase());
for(int i=0;i<s1.length();i++){
System.out.println("s1中的第"+i+"个字符是:"+s1.charAt(i));
}
System.out.println("s1+s2="+s1+s2);
if(s1.compareTo(s2)==0)
System.out.println("字符串s1与s2相等");
else
System.out.println("字符串s1与s2不相等");
if(s1.indexOf(s2)!=-1){
System.out.println("字符串s2是s1的子串");
System.out.println("字符串s2在s1中的位置是:"+s1.indexOf(s2));
}
else
System.out.println("字符串s2不是s1的子串");
System.out.println("经过上述操作:");
System.out.println("字符串s1仍然为:"+s1);
System.out.println("字符串s2仍然为:"+s2);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?