第五周课程总结与报告

实验三 String类的应用
•实验目的
•掌握类String类的使用;
•学会使用JDK帮助文档;
•实验内容

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

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

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

一.实验代码

package Fuck;

public class Fuck {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         String s = "this is a test of java";
         int n = (s.split("s")).length - 1;
         System.out.println("s出现的次数" + n);
         
         int t = (s.split("is")).length - 1;
         System.out.println("is出现的次数" + t);
         
         int g = (s.split(" is ")).length - 1;
         System.out.println(" is 出现的次数" + g);
         
         StringBuffer str = new StringBuffer(s);
         str = str.reverse();
         System.out.println(str);
    }
}

(1)实验结果

二.实验代码

public class RNG {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(" 加密还是解密 ?");
        Scanner input=new Scanner(System.in);
        int x;
        if(input.nextLine().equals("解密")){
           x=0;
           }
        else {
           x=1;
        }
        String s=input.nextLine();
        char[] ch=s.toCharArray();
        if(x==1) {
            for(int i=0;i<ch.length;i++){
               ch[i]=(char)(ch[i]+3);
        }
        }else {
            for(int i=0;i<ch.length;i++){
                ch[i]=(char)(ch[i]-3);
            }
         }
        s=s.valueOf(ch);
        System.out.println(s);


	}

}

运行截图

三,实验代码

public class FUCK1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 public static void main(String[] args) {
		        // TODO Auto-generated method stub
		        String s="ddejidsEFALDFfnef2357 3ed";
		        char[]ch=s.toCharArray();
		        int sd=0,sx=0,sf=0;
		        for(int i=0;i<ch.length;i++) {
		            if(ch[i]>='A'&&ch[i]<='Z') {
		                sd++;
		            }
		            else if(ch[i]>='a'&&ch[i]<='z'){
		                sx++;
		            }
		            else {
		                sf++;
		            }
		        }
		        System.out.println(sd);
		        System.out.println(sx);
		        System.out.println(sf);


	}

}

运行截图

总结:
好嗨哦,感觉人生已经到达了高潮,感觉人生已经到达了巅峰。

原文地址:https://www.cnblogs.com/dxl1314520/p/11600152.html