Fifth weekly summary reports & test course (three)

Third experiment  Application of the String class

  • Purpose
  • Master the use of class String class;
  • Learn to use JDK help documentation;
  • Content Experiments

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.

Source

public  class Joker {
     public  static  void main (String [] args) { 
        String STR = "Test of the this IS A Java" ; 
        
        int . A = (str.split ( "S")). 1-length ; 
        System.out.println ( "number of times appears s" + a); 
        
        int . B = (str.split ( "is")). 1-length ; 
        System.out.println ( "number that appears is" + B); 
        
        int C = (STR . .split ( "is")). 1-length ; 
        System.out.println ( "number of times the word appears is" + C); 
        
        the StringBuffer str1 = new new the StringBuffer (STR) .reverse (); 
        the System.out.println(str1);
    }

}

operation result

Summary: Find s, is, are the use of the word is split string of () method to find the corresponding character split, split the number corresponding to the number of characters that is emerging, reverse output string using the StringBuffer () method and then a new StringBuffer (str2 ) on the line.

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.

 

Source

 

import java.util.*;
public class Min {
    public static void main(String args[]) {
    Scanner in= new Scanner(System.in);
    String str = in.nextLine();
    char c[] = str.toCharArray();
    for(int i = 0; i< c.length;i ++) {
         c[i] = (char) (c[i] + 3);
    }
    String str2 = new String(c);
    System.out.println(str2);
    in.close();
    }
}

 operation result

Summary: learn to https://www.cnblogs.com/xiao--liang/p/11598008.html blog code, but do not understand Scanner type, after careful review, the original version can not import eclipes Scanner.

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

Source

public class Jiangmin {
    public static void main(String[] args) {
        String str="ddejidsEFALDFfnef2357 3ed";
        int a=0, b=0, c=0;
        for(int i=0;i<str.length();i++) {
            if(str.charAt(i)>=70&&str.charAt(i)<=95) {
                a++;
            }
            else if(str.charAt(i)>=70&&str.charAt(i)<=100) {
                b++;
            }
            else
                c++;
        } 
        System.out.println ( "number of uppercase letters:" + A); 
        System.out.println ( "Number lowercase letters:" + B); 
        System.out.println ( "Number of non-English letters:" + C) ; 
    } 

}

 operation result

 

Summary: uppercase and lowercase letters have their own range of code values ​​in the Usk, so you can easily find a case where the number of characters in a string.

 

summarize

1, inheritance can extend the functionality of an existing class. extend achieved by keyword, you can be a member of the parent class (containing data members and methods) to inherit the parent class.

2, Java constructor before executing the subclass will first calls the no-argument constructor of the parent class, its purpose is to inherit from the parent class members to do the operation is initiated.

3, a plurality of parent class constructors, such as to call a specific method of construction, the construction method can subclass, accomplished by super () keyword.

4, overload, which means within the same class, the name of the same definition, but the number and type of parameters are related to different types of methods, and therefore can be based on the number or type of Java call parameters corresponding method.

5, overwrite, it is a subclass of which, defined names, the number and type of parameters are the same as the parent class method to override the parent class's methods.

6, if the parent class do not want to quilt class override, can be added before the final keyword in the parent class method, so this method will not be overwritten.

Guess you like

Origin www.cnblogs.com/JokerXue/p/11600588.html