Fifth week Lessons Learned & test report

The difference between this and super

Point of difference

this

super

Property access

Access to the same kind of property, from the parent class if this class does not have to continue to look for this property

Access the parent class attributes

method

Access methods in this class, if this is not a class this method from the parent class continue to look for

Direct access to the parent class method

Call the constructor

Call this class structure, it must be placed on the first line of the constructor

Call the parent class constructor, it must be placed on the first line of the subclass constructor

special

It represents the current object

No such concept

note:

this and super can call the constructor, but both the city can not occur simultaneously, since both call the constructor city must be placed first line constructor.

Whatever the subclass operation, and ultimately we must first call the constructor of the parent class.

Access restrictions: a subclass can not directly access the parent class's private members, but subclass the parent class of non-private methods can be called.

 

 

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.
package test;

public class work {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        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(count);
    }

}

 

 

 

package test;

public class work {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String str = "this is a test of java";
        String s = "is";
        String[] arr = (","+str.toLowerCase()+",").split(s);
        System.out.println(arr.length - 1);
    }

}

 

 

 

 

package test;

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

 

 

 

 

package test;

public class work {
      public static void main(String[] args) {
            
          StringBuffer str = new StringBuffer("this is a test of java");
          System.out.println(str.reverse());
          }
      }

 

 

package first;
import java. util.*;
public class test {
      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);
              }
          }

 

 

package first;
import java. util.*;
public class test {
    public static void main(String[] args) {
                String str="ddejidsEFALDFfnef2357 3ed"; 
                int d=0,x=0,f=0; 
                char c[]=str.toCharArray(); 
                for(char a:c){ 
                    if(a>='a'&&a<='z'){ 
                       D ++ ; 
                    } 
                    the else  IF (A> = ' A ' && A <= ' the Z ' ) { 
                        X ++ ; 
                    } 
                    the else { 
                        F ++ ; 
                    } 
                } 
                the System. OUT (.println " lowercase letters Number: " + X ); 
                . the System OUT .println ( " uppercase letters number: " + D);
                The System. OUT .println ( " non-English alphanumeric: " + F); 
            } 
        }

 

 

Guess you like

Origin www.cnblogs.com/shihao0701/p/11593576.html