Java test report (iii) the fifth week & Lessons Learned

String class experimental use three
experimental purposes
master class using the class String;
learn to use JDK help files;
experiment content
1. Known string: "this is a test of java " required to do the following requirements :( source code. results screenshot.)
count the number of letters in the string s appears.
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.

Experiment Code 1):

package 实验室;
public class demo3 {
    public static void main(String[] args) {
        String str="this is a test of java";
        int count=0;
        char c[]=str.toCharArray();
        for(int i=0;i<c.length;i++){
            if(c[i]=='s'){
                count++;
            }           
         }
        System.out.println("s出现了"+count+"次");
            
    }
}

Screenshot operating results:

Experiment Code 2):

package 实验室;

public class demo2 {
    public static void main(String args[]) {
        String str = "This is a test of java";
        int count=0;
        
        String[] s=str.split(" ");
        for(String e:s) {
            if(e.equals("is")) {
                count++;
            }
        }
        System.out.println("is出现了"+count+"次");
    }
}

Screenshot operating results:

Experiment Code 3):

package 实验室;

public class demo1 {
    public static void main(String args[]) {
        String str="This is a test of java";
        int count=str.indexOf("is");
        System.out.println(count);
    }

}

Screenshot operating results:

Experiment Code 4):

package 实验室;

public class demo4 {
        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]);
            }
            
        }
}

Screenshot operating results:

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. (Did not think method)

experiment code:

package 实验室;

import java. util.*;
public class demo5 {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        String str1 = sc.nextLine();
        char c[] = str1.toCharArray();
        char a[] = new char[str1.length()];
        int i,j=0;
        if(str1.length()==1) {
            System.out.println(c);
        }
        else if(str1.length()==2) {
            System.out.print(c[1]);
            System.out.print(c[0]);
        }
        else {
            for(i = c.length-3;i<c.length;i++) {
                a[j] = c[i];
                j++;
            }
            for(i=0;i<c.length-3;i++) {
                a[j]=c[i];
                j++;
            }
        }
        System.out.println(a);
    }
}

Source Code: https://www.cnblogs.com/leisidiya/p/11580804.html

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

package 实验室;

public class demo6 {
        public static void main(String[] args) {
            String str="ddejidsEFALDFfnef2357 3ed";
            int x=0,y=0,z=0;
           char c[]=str.toCharArray();
           for(char e:c) {
               if(e>='a'&&e<='z'){ 
                 x++; 
                } 
                else if(e>='A'&&e<='Z'){ 
                  y++; 
                } 
                else{ 
                    z++; 
                } 
            } 

            System.out.println("大写字母数:"+x);
            System.out.println("小写字母数:"+y);
            System.out.println("非英语字母数:"+z);
        }

    }

Screenshot operating results:

Learning Summary:
what they learned:
1, learning the basic concepts of inheritance and usage:
1)
2)
3) understanding of the relationship between parent and child classes:
4) understand and master the implicit statement "super ();" The usage:
while "super" can call the constructor of the parent class (non-private: private), properties, methods, and so on.
5) learning the overloading and override methods:

2, a multi-state study:
3, learning class design and analysis:

Learning deficiencies at:
1, can not complete the task independently;
2, this week there is no time to digest what they have learned to do cause problems Difficult;
3, can not judge the whole (also cite a trans-difficult): Using the same knowledge can not make two or more of the same kinds of questions programming problem;
4, write code or not stringent enough, many compilation errors;
such as
that last week on the learning needs improvement :( no direction improvements proposed last week are not fully somehow)
need big brother advice.

PS: classroom problem: the use of sounds inheritance functional output of a puppy or kitten, that enter "dog", the output "wangwangwang", enter "cat", the output "miaomiaomiao".
Experiment code:? ? ? ? ?

Guess you like

Origin www.cnblogs.com/ImportantMagic/p/11599992.html