第五周学习总结&实验报告三

实验报告:

实验一已知字符串:"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);

}

}

猜你喜欢

转载自www.cnblogs.com/tengziqiang/p/11598257.html