Fifth weekly summary reports & test course (three)

Lessons Learned
a class inheritance format
1. In Java extends keyword can be declared by a class from another class is inherited, usually in the form below:

class 父类 {}
class 子类 extends 父类 {}

2. subclass can extend the parent class
3. Only allow multilayer inheritance, multiple inheritance is not allowed
II: method overloading and override
override: refers to a subclass defines a method with the same name in the parent class, but to consider authority, quilt class override the method can not have more stringent than the parent class method of access.
overload: the same class method of the same name with different parameters
. the basic concept of four abstract classes
1 contains an abstract method of class must is an abstract class
2. abstract classes and abstract methods should use the abstract key statement:
3. abstract method requires only a statement without the need to implement

Experimental Report
1. Known string: "this is a test of java " required to do the following requirements :( source code, the 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.
(1) and experiment code screenshot

public class test {
    
          public static void main(String[] args) {
              String str = "this is a test of java";
              char c[] = str.toCharArray() ;
              int i=0;
              for(char J:c) {
                  if(J=='s') {
                      i++;
                  }
              }
              System.out.println("s的数量为:"+i);
          
        }
}


(2) and experiment code screenshot

public class TEST2 {
    public static void main(String[] args) {
        String str=new String("this is a test of java");
        int count=0,a=0;
        while(str.indexOf("is",a)!=-1) {
            count++;
            a=str.indexOf("is",a)+2;
        }
        System.out.println("is出现的次数:"+count);

    }

}

(3) and experiment code screenshot

public class Test3 {
     public static void main(String[] args) {
         String str = "this is a test of java";
         String a[];
         int count=0;
         a=str.split(" ");
         for(String c:a){
             if(c.equals("is")){
                 count++;
             }
         }
         System.out.println("单词is的数量:"+count);
     }
}

(4) and the experiment code screenshot

public class Test4 {
      public static void main(String[] args) {

          StringBuffer str = new StringBuffer("this is a test of java");
          System.out.println(str.reverse());
          }
}

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 and screenshots

public class TEst5 {

        public static void main(String[] args) {
            String str="ddejidsEFALDFfnef2357 3ed";
            int a=0,b=0,m=0;
            char[] c=str.toCharArray();
            for(int i=0;i<str.length();i++)
            {
                if(c[i]>='a'&&c[i]<='z')
                {
                    a++;
                }
                else if(c[i]>='A'&&c[i]<='Z')
                {
                    b++;
                }
                
                else {
                   m++;
                }
            }
            System.out.println("小写字母出现的次数:"+a);
            System.out.println("大写字母出现的次数:"+b);
            System.out.println("其他字符出现的字数:"+m);
            
        }

    }

Summary:
1. The second question less likely, the first question most talked teacher in the class, these methods on the books, will soon be able to solve,
2. after school to read more.

Guess you like

Origin www.cnblogs.com/jiajia2333/p/11600769.html