首页 > 其他 > 详细

第五周课程总结&试验报告(三)

时间:2019-09-27 01:22:37      阅读:66      评论:0      收藏:0      [点我收藏+]

实验内容

1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)
1.统计该字符串中字母s出现的次数。

代码:

package test;
public class test {    
    public static void main(String [] args){ 
        int sum = 0;
        String str = "this is test of java";
        char c[] = str.toCharArray();
        for(int i = 0;i<c.length;i++) {
            if(c[i] == 's') {
                sum++;
            }
        }
        System.out.println(sum);
    }
}
2.统计该字符串中子串“is”出现的次数。

代码:

package test;
public class test {    
    public static void main(String [] args){ 
        int sum = 0;
        String str = "this is test of java";
        char c[] = str.toCharArray();
        for(int i = 0;i<c.length;i++) {
            if(c[i] == 'i'&&c[i+1] == 's') {
                sum++;
            }
        }
        System.out.println(sum);
    }
}
3.统计该字符串中单词“is”出现的次数。

代码:

package test;
public class test {    
    public static void main(String [] args){ 
        int sum = 0;
        String str = "this is test of java";
        char c[] = str.toCharArray();
        for(int i = 0;i<c.length;i++) {
            if(c[i] == ' '&&c[i+1] == 'i') {
                sum++;
            }
        }
        System.out.println(sum);
    }
}
4.实现该字符串的倒序输出。

代码:

package test;

public class ban {
    public static void main(String[] args) {
        String str = "this is test of java";
        
        for (int j = str.length()-1; j>=0; j--) {
            char a = str.charAt(j);
            System.out.print(a);
       }
    
    }
}

技术分享图片

2.请编写一个程序,使用下述算法加密或解密用户输入的英文字串。要求源代码、结果截图。

技术分享图片

3.已知字符串“ddejidsEFALDFfnef2357 3ed”。输出字符串里的大写字母数,小写英文字母数,非英文字母数。

第五周课程总结&试验报告(三)

原文:https://www.cnblogs.com/yuanqizhizhi/p/11595133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!