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

实验三 String类的应用

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

1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)

  • 统计该字符串中字母s出现的次数。
  • 统计该字符串中子串“is”出现的次数。
  • 统计该字符串中单词“is”出现的次数。
  • 实现该字符串的倒序输出。

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

 

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

1.1实验代码

package jave;
public class qq {
    public static void main(String[] arges) {
        String str1 ="this is a test of java";
        char a[]=str1.toCharArray();
        int count=0;
        for(int i=0;i<a.length;i++) {
            if(a[i]=='s') {
                count++;
            }
        }
        System.out.print(count);
    }
    
}

 

 1.2实验代码

package jave;
public class dd 
{
            public static void main(String args[]) 
            {
            int count=0;
            String str1 = "this is a test of java";
                char a[]=str1.toCharArray();
                for(int i=0;i<a.length;i++)
                {
                    if(a[i]=='i' && a[i+1]=='s')
                    {
                        count++;
                    }
                
                 }
                System.out.println(count);
            }

}

 

 1.3实验代码

package jave;
public class  dd{
    public static void main(String[] arges) {
        String str ="this is a test of java";   
        int count=0;
        if(str.contains("is")) {
            count++;        
        }
        System.out.print(count);
    }
}

 

 1.4实验代码

package jave;
public class dd
{
            public static void main(String args[]) 
            {
            
            String str1 = "this is a test of java";
            char a[]=str1.toCharArray();
            int count=a.length-1;
                for(int i=count;i>=0;i--)
                {
                    
                System.out.print(a[i]);
                }
            }    
}

 学习总结:

1.这周作业差不多都是上周老师上课讲的,主要运用了string类

2.这周学习了继承和抽象

3.final关键字

(1)使用final声明的类不能有子类

(2)使用final声明的方法不能被子类覆写

(3)使用final声明的变量为常量,常量不可以修改

 

posted @ 2019-09-27 22:09  时光碎片  阅读(161)  评论(0编辑  收藏  举报