编写一个Java程序,要求定义两个字符串str1为"Hello”,str2为“World”,要求输出
1.显示str, str为str1和str2相连
2.显示str的长度
3.显示str的第8个位置的字符
4.显示str中字符串”or“第一次出现的位置
5.将str转变为小写并显示
6.将str转变为大写并显示
要求将程序运行结果截图,源代码截图 并附上程序源代码文件。
public class zfc {
public static void main(String[] agrs) {
String str1="Hello";
String str2="World";
String str=str1+str2;
System.out.println(str);
System.out.println(str.length());
System.out.println(str.charAt(8));
System.out.println(str.indexOf("or"));//第一次
System.out.println(str.toLowerCase());//转化成小写
System.out.println(str.toUpperCase());//转换成大写
}
}
考察相关字符串的知识
字符串“+”号相连就是字符串相连
string.length();字符串的长度
str.charAt(i);返回下标为i的位置的字符
str.indexOf(“or”);返回or第一次出现的地方
toLowerCase();
toUpperCase();
转换大小写
新手入门写的不好请多指教。
748




被折叠的 条评论
为什么被折叠?



