Fifth week experiment Summary & Report III

Summary: This week learning results did not meet the target, using a variety of methods are not very familiar with, still have to understand the contents of the book, read more books, the weekly experiments do!

 The following is a basic knowledge of this week:

A . The method may be configured to initialize the attribute class, the class constructor with the same name, no return value type declaration, if not explicitly defined in the class constructor is automatically configured to generate a non-parametric do nothing a method, in a class constructor can be overloaded, but each has at least one class constructor.

Two .String class in Java more in particular, String may be used directly or assignment is instantiated by the constructor. In String used when comparing the content equals method, and " == " to compare only the address value of the two strings. Once declared the contents of the string can not be changed.

Three . In Java use this keyword may represent the current object, " this. Properties" you can call this class of property, by " this. Method () " other methods in this class can be called by this () call the constructor for this class of forms.

Four . Use an array of objects to declare an array into an array of open space and two-step. After opening up space for the contents of each element in the array is null .

Six .Java use package can achieve more than the collaborative development model, the class name to avoid repetition of the trouble. Use package keyword to a class into a package, use the import statement to import an existing package.

Seven .Java access control permissions are divided into 4 Zhong, Private , default , protected , public .

Eight . Class inheritance format

In Java use extends inheritance keywords to complete the class

Nine . Access Restrictions

Subclass can not directly access the parent class's private members, but subclasses of the parent class non-private method calls

Ten . Subclass object instantiation

After subclass object and then call you must first call the parent class constructor in subclass before instantiating its own constructor.

Eleven . Overwrite method

1. In the inheritance relationship also exists the concept of overwriting method, i.e. a method with the same name as the parent class is defined in the subclass.

2. The method must take into account when override permissions, quilt class override the method can not have more stringent than the parent class method of access.

Twelve .super role of keywords

Use super may call the constructor of the parent class, the conventional method, from a subclass properties.

thirteen. Final

1. Use final declaration of the class can not have subclasses;

2. Use final declaration of method can not be overwritten subclasses;

3. Use final variable declaration and become constant;

 

 

Experiment three String application class 

1. Known string: "A Test of the this IS Java." Required to perform the following operations: (source code requirements, results screenshot.)

 

First, the statistics in the string of letters s number of occurrences .

Experiments Source:

package first;

public class test {

    public static void main(String[] args) {
                String juzi = "this is a test of java";
                char c[] = juzi.toCharArray() ;
                int i=0;
                for(char a:c) {
                    if(a=='s') {
                        i++;
                    }
                }
                System.out.println ( " number with the letter s: " + I); 
            } 
        }

Experimental results

 

 

 

Second, the statistical neutron string the string number "is" appears.

Experiments source

package first;

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

Experimental results

 

 

 

Third, the statistics word in the string number "is" appears.

Experiments Source:

package first;

public class test {
      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++;
                      }
                  }
                  . The SystemOUT .println ( " word number is: " + COUNT); 
              } 
          }

Experimental results

 

 

 

Attaining reverse the string is output.

Experiments Source:

package first;

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

Experimental results

 

 

 

Two . 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.

Experiments source

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

Experimental results

 

Third, the well-known string " ddejidsEFALDFfnef2357 3ED ." The output string in the number of capital letters, lowercase letters count, the number of non-English letters .

Experiments source

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

Experimental results

 

 This week's experiment in front of a few simple questions, to back a bit harder, need some constructor, read in conjunction with the information and the investigation was finished writing! Still have to learn the knowledge of the book.

Guess you like

Origin www.cnblogs.com/LUMO/p/11590196.html