2021-1-13
1. Definition of the class
2. Use of objects
3. Member variables and local variables
4.private keyword
5.this keyword
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
6. Package
7. Construction method
Points to note for the parameterless structure
and the parameterized structure
8.Api introduction
Chinese version download link: https://pan.baidu.com/s/19ISxIVuZnogDGjV6Wor-PA
9. String class (plus case examples)
String construction method
string comparison
user login case
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
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
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
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
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
10.StringBuilder
StringBuilder construction method
StringBuilder add and reverse
StringBuilder and Strng conversion
case