实验报告:
实验一已知字符串:"this is a test of java".按要求执行以下操作:
1:统计该字符串中字母s出现的次数
实验代码:
package Java11;
public class TZQD {
public static void main(String[] args) {
String r = "this is a test of java";
int sum = 0;
char[] c = r.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == 's') {
sum++;
}}
System.out.println("S的个数为"+sum);
}
}