On the first day of learning API, you have to know this! --------Three days without blog, full of guilt

Keywords: JDK Java less

The original String type is so powerful, I just thought it was used to define a String. Next is a day to learn String type by doing homework.
At the end of the article, there is the help document of JDK API 1.6 in Chinese. It is necessary for novices to get it for free! Brother, I have been looking for it for a long time.

1. Use code to demonstrate the usage of the following methods in String class

(1)boolean isEmpty(): judge whether the string is empty or not. If it is empty, return true
 (2)char charAt(int index): returns the characters on the index
 (3)String toLowerCase(): string converted to lowercase
 (4)String toUpperCase(): string to uppercase
 (5) String reply (char oldchar, char newchar): replace old characters with new ones
 (6) String reply (string old, string newstr): replace the old string with the new one
 (7)String trim(): remove the spaces at both ends of the string

I just test one by one and write all the functions in one class. Note that they are all written in the code comments, which is very simple.

package cn.demo01;
/*
 * Explain what the following comment () means. For example (1)boolean isEmpty(): judge whether a string is empty, and return true if it is empty
 *       All methods of String type introduction return value method name method function description
 *       This explanation format is the Chinese help document of Java API, which is available in my blog for free!
 */
public class stringDemo {
	public static void main(String[] args) {
		
		function_1();
		function_2();
		function_3();
		function_4();
		function_5();
		function_6();
		function_7();
	}
	/*
	 * (7)String trim(): Remove spaces at both ends of string
	 */
	public static void function_7(){
		String s = new String("      acvsjavadfasf      ");
		System.out.println("(7)example"+s);
		String s1 = s.trim();
		System.out.println(""+s1);
	}
	
	/*
	 * (6)String repalce(String old, String newstr): Replace the old string with the new one
	 */
	public static void function_6(){
		String s = new String("acvsjavadfasf");
		String s1 = s.replace("java","AAAaaa");
		System.out.println("(6)"+s1);
		
	}
	
	/*
	 * (5)String repalce(char oldChar, char newChar): Replace the old character in the string with the new character
	 */
	public static void function_5(){
		String s = new String("acvsjavadfasf");
		String s1 = s.replace('j', '6');  //Only one character can be replaced. Remember to add ''
		System.out.println("(5)"+s1);	
	}
	
	/*
	 * (4)String toUpperCase(): String to uppercase
	 */
	public static void function_4(){
		String s = new String("acvsdfasf");
		String s1 = s.toUpperCase();
		System.out.println("(4)"+s1);
	}
	
	/*
	 * (3)String toLowerCase(): String to lowercase
	 */
	public static void function_3(){
		String s = new String("ABCDEFG");
		String s1 = s.toLowerCase();
		System.out.println("(3)"+s1);
	}
	
	/*
	 * (2)char charAt(int index): Return characters on index
	 */
	public static void function_2(){
		String s = new String("abcdef");
		char c = s.charAt(3);
		System.out.println("(2)"+c);
	}
	
	/*
	 * (1)boolean isEmpty(): Judge whether the string is empty, and return true if it is empty
	 */
	public static void function_1(){
		String s = new String("123456");
		boolean b = s.isEmpty();
		System.out.println("(1)"+b);
		
	}
}

2. Analyze the following requirements and implement them in Code:

(1) Define the following method: public static String getPropertyGetMethodName(String property);
(2) The parameter of this method is String, which means the name of the member variable given by the user. The return value is String, and the return value is the name of the get method corresponding to the member variable
 (3) For example, when the user calls this method, the given parameter is "name", and the return value of this method is "getName"

I didn't understand the meaning of the subject. Maybe I misunderstood the subject

package cn.demo02;
/*
 * Analyze and code the following requirements:
	(1)Define the following method: public static String getPropertyGetMethodName(String property);
	(2)The parameter of this method is String, which means the name of the member variable given by the user. The return value is String, and the return value is the name of the get method corresponding to the member variable
	(3)For example, when the user calls this method, the given parameter is "name", and the return value of this method is "getName"

 */
public class SetMethod {
	public static void main(String[] args) {
		System.out.println(getPropertyGetMethodName("Zhang San"));
	}
	public static String getPropertyGetMethodName(String property){
		String name = property;
		return name;
		
	}
}

3. Analyze the following requirements and implement them in Code:

(1) Define number string array {"010", "3223", "666", "7890987", "123123"}
(2) Determine whether the number strings in the number string array are symmetrical (the first number is equal to the last number, the second number is equal to the last number, and so on), and output one by one
 (3) For example: 010 is symmetric, 3223 is symmetric, 123123 is not symmetric
 (4) The number of symmetric strings in the array to be finally printed

Tip: loop through each character of the string, and then compare the first and last, the second and the last...

I'm right about the code, but the result is one less.

package cn.demo03;
/*
 * (1)Define number string array {"010", "3223", "666", "7890987", "123123"}
	(2)Determine whether the number string in the number string array is symmetrical (the first number is equal to the last number, the second number is equal to the last number, and so on), and output one by one
	(3)For example: 010 is symmetric, 3223 is symmetric, 123123 is not symmetric
	(4)The number of symmetric strings in the array to be finally printed
	
	Tip: loop through each character of the string, and then compare the first and last, the second and the last...
 */
public class Judge {
	public static void main(String[] args) {
		function();
	}
	
	public static void function(){
		String[] st = {"010","3223","666","7890987","123123"};
		int count = 0;
		int c = 0;//Number of final prints, using counter
		for(int i = 0;i < st.length;i++){
			String s = st[i];
			for(int j = 0;j <s.length()/2;j++){
				if(s.charAt(j) != s.charAt((s.length()-1))-j){
					count =0;
					
				}else {
					count = 1;
					
				}
					
			}
			if(count == 1){
				System.out.println(st[i]);  //Print out each symmetric string
			}
			c = c+count;
			
		}
		System.out.println("Number of symmetric strings: "+c);
		
	}
}


JDK API 1.6 Chinese version:
Link: link: https://pan.baidu.com/s/1owvwlhxnzvw9m8e8ifstkg
Extraction code: o0oj

Published 11 original articles, won praise 4, visited 500
Private letter follow

Posted by louisp on Mon, 16 Mar 2020 21:31:05 -0700