Fifth week Lessons Learned & third test report

Application third experiment String class

Purpose

Master the use of class String class;
learn to use JDK help documentation;

SUMMARY experiment
1. Known string: "this is a test of java " required to do the following requirements :( source code, the results screenshot).

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

2. Write a program, using the following algorithm to encrypt or decrypt the English string input by the user. It requires source code, the results screenshot.

3. Given the string "ddejidsEFALDFfnef2357 3ed". The output string in the number of capital letters, lowercase letters count, the number of non-English letters.

First, the experiment
first question
experiment code

public class Dome1 {
     public static void main(String[] args) {
         String str="This is a test of java";
         int x=0;
         int y=0;
         for(int i=0;i<str.length();i++) {
             if(str.charAt(i)=='s')
                 x++;
             if(str.charAt(i)=='i'&&str.charAt(i+1)=='s')
                 y++;
        }
         System.out.println("字母s出现的次数:"+x);
         System.out.println("子串is出现的次数:"+y);
     }
}

The results

experiment code

public class Dome2 {
    public static void main(String[] args) {
            String str="This is a test of java";
            String s[]=str.split(" ");
            int count=0;
            for(int i=0;i<s.length;i++) {
                if(s[i].equals("is"))
                    count++;
            }
            System.out.println("该字符串中单词“is”出现的次数:"+count);
}
}

The results

experiment code

public class Dome3 {
    public static void main(String[] args) {
        String str="This is a test of java";
        char s[] = str.toCharArray();
        for (int i=s.length-1;i>=0;i--) {
            System.out.print(s[i]);
        }
        
    }

}

Experimental results

The second question
experiment code

package Work;

import java.util.*;

public class Dome4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一串大于3个字符的英文字符串或解密字符串");
        String x= sc.nextLine();
        char y[]=x.toCharArray();
        char z[]=new char[y.length];
        int i=0,j=0;
        for(i=y.length-3;i<y.length;i++) {
            z[j]=y[i];
            j++;
        }
        for(i=0;i<y.length-3;i++) {
            z[j]=y[i];
            j++;

        }
        String str=String.valueOf(z);
        System.out.println("加密或解密结果如下:");
        System.out.print(z);

}
}

The results

problems encountered

found If a character is less than three, then do not have time-sensitive during operation, so this program is only available in three-character string input is greater than the
third question
experiment code

public class Dome5 {
    public static void main(String[] args) {
        String str="ddejidsEFALDFfnef2357 3ed";
        int x=0,y=0,z=0;
        for(int i=0;i<str.length();i++) {
            if(str.charAt(i)>=65&&str.charAt(i)<=90) {
                x++;
            }
            else if(str.charAt(i)>=97&&str.charAt(i)<=122) {
                y++;
            }
            else;
               z++; 
        }
        System.out.println("大写字母数:"+x);
        System.out.println("小写字母数:"+y);
        System.out.println("非英语字母数:"+z);
    }

}

Experimental results

Programming summary
of this subject is all about how to use the method of the String class, the first big issue is basically the class the teacher has said before, the second big issue are more difficult to apply the method Scanner class, after facing a string after split points into character of the character moves in the split programmed into the array. The third big issue is the test of our familiarity with the ASCII letters, followed by the string classification

Second, the Lessons Learned
this week we learned about inheritance and abstract classes, but also a little bit of contact with the polymorphism
1, inheritance
can inherit properties of parent child class through inheritance


In this regard, we also learn in succession to a new approach, "override", which is overloaded with previously learned different methods

in succession and there are two key --super Final
①super
role of super constructor is also invoked, but a little different, and this

②final
he is an end, you can stop using the parent class

2, abstract class
abstract class is a special method used as a parent class

3, polymorphism

That's what I learned this week, is now beginning to learn level object-oriented articles, and also from some simple content became complicated, but I think the teacher told us very well, the program will be difficult to pass during class understand the concept becomes easy to understand, we have to digest very well.

Guess you like

Origin www.cnblogs.com/xzy999123/p/11599734.html