Fifth week Lessons Learned & test report

Fifth week Lessons Learned & test report

Application third experiment String class

Purpose
master the use of class String class;
learn to use JDK help documentation;
test content

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

The number of letters in the string s occurs statistics.
The string neutron count the number of times the string "is" appears.
The number of words in the string "is" appears in the statistics.
Achieve reverse the string is output.

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.

1. Experimental Source

public class new2{

    public static void main(String[] args) {
       String str = "this is a test of java";
       int i = 0;
       int q = 0;
       for(i = 0;i < str.length();i++) {     //利用for循环统计字符串总长度
           char a = str.charAt(i);
           if(a == 's') {
           q++;
       }
    }
       System.out.println("s出现的次数为:" +q);
       int b = str.indexOf("is");
       System.out.println("子串is出现的次数为:"+b);    
       int e = (str.split(" is ")).length-1;
       System.out.println("单词is出现的次数为:"+e);     //split函数
       StringBuffer r = new StringBuffer ("this is a test of java");   
       System.out.println("字符串的倒序输出:"+r.reverse());   
}
}

Experimental results

2. Experimental Source

import java.util.*;
public class new2{

    public static void main(String[] args) {
         System.out.println("输入英文字符串:");
            Scanner ad=new Scanner(System.in); 
            String str=ad.next();//读取字符串
            char t[]= str.toCharArray();
            System.out.println("加密后结果:");
            for(char r:t) {
                System.out.print((char)(r+3));
         }
     }
}

Experimental results

3. Experiment Source

public class new2 {

    public static void main(String[] args) {
         String str="ddejidsEFALDFfnef2357 3ed";
            
            char a[]=str.toCharArray();
            int x=0,y=0,z=0;
            for(int i=0;i<a.length;i++){
                if(a[i]>='A'&&a[i]<='Z'){
                    x++;//计算大写字母数量
                }
                else if(a[i]>='a'&&a[i]<='z'){
                    y++;//计算小写字母数量
                }
                else {
                    z++;//计算除开英文字母其他内容数量
                }
            }
            System.out.println("大写字母数:"+x);
            System.out.println("小写字母数:"+y);
            System.out.println("非英文字母数:"+z);

    }

}

Experimental results

Fifth weekly summary

1. Since this and super can call the constructor, then the two are not occur simultaneously, since both call the constructor must be placed when they are the first line of the constructor, in addition, be noted that, no matter how subclass operation, ultimately we must first call the constructor of the parent class.

2. Definition of the usage rule abstract class as follows:

(1) contains an abstract method of class must be abstract class:
(2) abstract classes and abstract methods should use the abstract keyword to declare: (3) abstract method simply declare without the need to implement:
(4) must be abstract class quilt class inheritance, a subclass of abstract class all the abstract methods (if it is not an abstract class) must be overridden

3. In fact, an abstract class is allowed constructor because abstract classes are still using the class hierarchy, but an abstract class, there are also individual attributes, so before the subclass is instantiated must be first to the parent class instantiated.

4.

Guess you like

Origin www.cnblogs.com/9557yxl/p/11599898.html