Java novice learning 2021-1-13 record the daily learning content (if there is any infringement, please contact to delete!!!)

2021-1-13

1. Definition of the class

Insert picture description here

2. Use of objects

Insert picture description here
Insert picture description here

3. Member variables and local variables

Insert picture description here
Insert picture description here

4.private keyword

Insert picture description here
Insert picture description here

5.this keyword

Insert picture description here
Use the this keyword to assign the value of a local variable to a member variable.
When the local variable and the member variable have the same name, you can use the this keyword
Insert picture description here

6. Package

Insert picture description here

7. Construction method

Points to note for the parameterless structure
Insert picture description here
and the parameterized structure
Insert picture description here

Insert picture description here

8.Api introduction

Insert picture description here
Chinese version download link: https://pan.baidu.com/s/19ISxIVuZnogDGjV6Wor-PA
Insert picture description here

9. String class (plus case examples)

Insert picture description here
String construction method
Insert picture description here
Insert picture description here
string comparison
Insert picture description here
user login case
Insert picture description here

package com.ei.login;

import java.util.Scanner;

/**
 * @author wc
 * @Date: 2021/01/18/19:07
 */
public class Login {
    
    
    public static void main(String[] args) {
    
    
        String username = "wc";
        String password = "123456";
        for (int i = 0; i < 3; i++) {
    
    
            Scanner s = new Scanner(System.in);
            System.out.println("请输入用户名");
            String name = s.nextLine();
            System.out.println("请输入密码");
            String psw = s.nextLine();
            if (name.equals(username) && psw.equals(password)) {
    
    
                System.out.println("登录成功");
                break;
            }
            if ((2-i)==0){
    
    
                System.out.println("次数用完,联系管理员解锁");
            } else {
    
    
                System.out.println("登录失败,你还有"+(2-i)+"次机会");
            }
        }
    }
}

Iterate over the string case
Insert picture description here

package com.ei.login;

import java.util.Scanner;

/**
 * @author wc
 * @Date: 2021/01/18/19:32
 */
public class CharArray {
    
    
    public static void main(String[] args) {
    
    
        Scanner s = new Scanner(System.in);
        System.out.println("请输入字符串");
        String s1 = s.nextLine();
        for (int i = 0; i < s1.length(); i++) {
    
    
            char c = s1.charAt(i);
            System.out.println(c);
        }
    }
}

Example of counting the number of characters
Insert picture description here

package com.ei.login;

import java.util.Scanner;

/**
 * @author wc
 * @Date: 2021/01/18/19:32
 */
public class CharArray {
    
    
    public static void main(String[] args) {
    
    
        Scanner s = new Scanner(System.in);
        System.out.println("请输入字符串");
        String s1 = s.nextLine();
        int num = 0;
        int Char = 0;
        int char1 = 0;
        for (int i = 0; i < s1.length(); i++) {
    
    
            char c = s1.charAt(i);
            if (c >= '0' && c <= '9') {
    
    
                num++;
            } else if (c >= 'a' && c <= 'z') {
    
    
                char1++;
            } else if (c >= 'A' && c <= 'Z') {
    
    
                Char++;
            }
        }
        System.out.println("数字:" + num);
        System.out.println("大写字母:" + Char);
        System.out.println("小写字母:" + char1);
    }
}

Splicing string case
Insert picture description here

package com.ei.login;

/**
 * @author wc
 * @Date: 2021/01/18/19:59
 */
public class Connect {
    
    
    public static void main(String[] args) {
    
    
        int[] arr = {
    
    1, 2, 3};
        String s = method(arr);
        System.out.println(s);
    }
    public static String method(int[] arr) {
    
    
        String s = "";
        s += "[";
        for (int i = 0; i <arr.length; i++) {
    
    
            if (i == arr.length - 1) {
    
    
                s += arr[i];
            } else {
    
    
                s += arr[i];
                s += ", ";
            }
        }
        s += "]";
        return s;
    }
}

Cutting string case
Insert picture description here

package com.ei.spilt;

import java.util.Scanner;

/**
 * @author wc
 * @Date: 2021/01/18/20:18
 */
public class Test {
    
    
    public static void main(String[] args) {
    
    
        Scanner s = new Scanner(System.in);
        System.out.println("请输入信息:");
        String info = s.nextLine();
        String[] split = info.split(",");
//        for (int i = 0; i < split.length; i++) {
    
    
//            System.out.println(split[i]);
//        }
        Student student = new Student(split[0],split[1]);
        System.out.println(student.getName()+student.getAge());
    }
}

summary
Insert picture description here
Insert picture description here

10.StringBuilder

StringBuilder construction method
Insert picture description here
Insert picture description here
StringBuilder add and reverse
Insert picture description here
Insert picture description here
StringBuilder and Strng conversion
Insert picture description here
case
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_49221590/article/details/112617930