JAVA第五周作业
Java实验报告三
第一题
1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)
(1)、统计该字符串中字母s出现的次数。
(2)、统计该字符串中子串“is”出现的次数。
(3)、统计该字符串中单词“is”出现的次数。
(4)、实现该字符串的倒序输出。
实验代码
(1)统计该字符串中字母s出现的次数。
public class Letter {
public static void main(String args[]) {
String str="This is a test of Java";
int count=0;
char c[]=str.toCharArray();
for(int i=0;i
if(c[i]=='s') {
count++;
}
}
System.out.println(count);
}
}
运行结果
实验代码
(2)、统计该字符串中子串“is”出现的次数。
public class Character {