Java实用类

一、枚举类型

1、枚举概念

枚举指由一组固定的常量组成的类型

2、枚举特点

1)类型安全

2)易于输入

3)代码清晰

3、实现操作
package javaapidemo0126.demo01;

public class Student {

    public String name;
    public String sex;

    public Student() {
    }

    public Student(String name, String sex) {
        this.name = name;
        this.sex = sex;
    }
}
package javaapidemo0126.demo01;

public class Test {

    public static void main(String[] args) {

        // 使用无参构造方法创建Student对象
        Student student1 = new Student();
        // 给属性赋值
        student1.name = "张三";
        student1.sex = "男";

        //
        Student student2 = new Student();
        //
        student2.name = "李四";
        student2.sex = "您好";

        // 直接给属性赋值,赋予的值可能不符合要求,所以需要对赋值进行判断
        if(!(student2.sex.equals("男") || student2.sex.equals("女"))) {
            System.out.println();
            student2.sex = "女";
        }
        System.out.println(student2.sex);

        // 枚举类型

    }
}

 运用枚举

package javaapidemo0126.demo02;

public enum Gender {

    // 枚举类
    男,女
}
package javaapidemo0126.demo02;

public class Student {

    public String name;
    public Gender sex; // 

    public Student() {
    }

    public Student(String name, Gender sex) {
        this.name = name;
        this.sex = sex;
    }
}
package javaapidemo0126.demo02;

public class Test {

    public static void main(String[] args) {

        //
        Student student1 = new Student();
        //
        student1.name = "张三";
        // student1.sex = "男"; 报错
        student1.sex = Gender.男; // 使用枚举类型

    }
}

 

二、Java API

1、java.lang

Enum、包装类、Math、String、StringBuffer、System

2、java.util

3、java.io

4、java.sql

......

三、包装类

1、包装类的概念

1)包装类把基本类型数据转换为对象

2)每个基本类型在java.lang包中都有一个相应的包装类

package javaapidemo0126.demo03;

import java.util.ArrayList;

public class ArrayListDemo01 {

    public static void main(String[] args) {

        ArrayList arrayList = new ArrayList();

        // 集合中不能存储基本数据类型
        // 系统会通过装箱的形式将基本数据类型直接转换为包装类对象
        arrayList.add(100);
        arrayList.add(200);
        arrayList.add(300);

    }
}

 

2、包装类的作用

1)提供了一系列实用的方法

2)集合不允许存放基本数据类型数据,存放数字时,要用包装类型

3、包装类的构造方法

所有包装类都可将与之对应的基本数据类型作为参数,来构造它们的实例

// public Byte(byte value)构造一个新分配的 Byte 对象,以表示指定的 byte 值
// public Short(short value)构造一个新分配的 Short 对象,用来表示指定的 short 值
// public Integer(int value)构造一个新分配的 Integer 对象,它表示指定的 int 值
// public Long(long value)构造新分配的 Long 对象,表示指定的 long 参数
// public Float(float value)构造一个新分配的 Float 对象,它表示基本的 float 参数
// public Double(double value)构造一个新分配的 Double 对象,它表示基本的 double 参数
// public Character(char value)构造一个新分配的 Character 对象,用以表示指定的 char 值
// public Boolean(boolean value)分配一个表示 value 参数的 Boolean 对象 

除Character类外,其他包装类可将一个字符串作为参数构造它们的实例

 
package javaapidemo0126.demo04;

public class Demo01 {

    public static void main(String[] args) {

        // 所有包装类都可将与之对应的基本数据类型作为参数,来构造它们的实例
        byte num1 = 100;
        Byte byte1 = new Byte(num1); // 创建对象
        System.out.println("num1 : " + num1); // num1 : 100
        System.out.println("byte1 : " + byte1); // byte1 : 100

        char char1 = '你';
        Character character1 = new Character(char1);
        System.out.println("char1 : " + char1); // char1 : 你
        System.out.println("character1 : " + character1); // character1 : 你

        // 除Character类外,其他包装类可将一个字符串作为参数构造它们的实例(可以查询API中构造方法)

        // 对于数值类型的包装类,这个字符串必须是数字形式,否则无法转换
        Integer integer1 = new Integer("123456"); // int类型
        // 字符串必须是数字形式,否则无法转换
        System.out.println("integer1 = " + integer1);

        // Integer interger2 = new Integer("qwerty");
        // System.out.println("interger2 = " + interger2); // 报错 NumberFormatException
        // NumberFormatException 数字格式化异常

        // 对于布尔类型的包装类,字符串内容只要是true(不区分大小写),结果就是为true
        // 其他字符串结果都是为false
        Boolean boolean1 = new Boolean("true");
        System.out.println("boolean1 : " + boolean1);

        Boolean boolean2 = new Boolean("TrUe");
        System.out.println("boolean2 : " + boolean2);

        Boolean boolean3 = new Boolean("false");
        System.out.println("boolean3 : " + boolean3);

        Boolean boolean4 = new Boolean("123a");
        System.out.println("boolean4 : " + boolean4);

        Boolean boolean5 = new Boolean("abc");
        System.out.println("boolean5 : " + boolean5);


        // 字符包装类构造方法中不能传递字符串
        // Character character2 = new Character("q"); // 报错

    }
}

注意事项:

1)Boolean类构造方法参数为String类型时,若该字符串内容为true(不考虑大小写),则该Boolean对象表示true,否则表示false

2)当Number(数值类型)包装类构造方法参数为String 类型时,字符串不能为null,且该字符串必须可解析为相应的基本数据类型的数据,否则编译不通过,运行时会抛出NumberFormatException异常

4、包装类中的静态常量
package javaapidemo0126.demo04;

public class Demo02 {

    public static void main(String[] args) {

        // 包装类中的静态方法,可以通过类名直接调用
        System.out.println("byte类型数据的范围:"+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE); // byte类型数据的范围:-128~127
        System.out.println("short类型数据的范围:"+Short.MIN_VALUE+"~"+Short.MAX_VALUE); // short类型数据的范围:-32768~32767
        System.out.println("int类型数据的范围:"+Integer.MIN_VALUE+"~"+Integer.MAX_VALUE); // int类型数据的范围:-2147483648~2147483647
        System.out.println("long类型数据的范围:"+Long.MIN_VALUE+"~"+Long.MAX_VALUE); // long类型数据的范围:-9223372036854775808~9223372036854775807
        System.out.println("float类型数据的范围:"+Float.MIN_VALUE+"~"+Float.MAX_VALUE); // float类型数据的范围:1.4E-45~3.4028235E38
        System.out.println("double类型数据的范围:"+Double.MIN_VALUE+"~"+Double.MAX_VALUE); // double类型数据的范围:4.9E-324~1.7976931348623157E308
        System.out.println("char类型数据的范围:"+Character.MIN_VALUE+"~"+Character.MAX_VALUE); // char类型数据的范围: ~
        //
        System.out.println("boolean类型对象:"+Boolean.TRUE); // boolean类型对象:true
        System.out.println("boolean类型对象:"+Boolean.FALSE); // boolean类型对象:false
    }
}

 

5、包装类中常用的方法

1)xxxValue():包装类转换成基本类型(包装类->基本类型)

2)toString():以字符串形式返回包装对象表示的基本类型数据(基本类型->字符串)

3)parsexxx():把字符串转换为相应的基本数据类型数据(Character除外)(字符串->基本类型)

4)valueOf():所有包装类都有如下方法(基本类型->包装类)

public static Type valueOf(type value)

除Character类外,其他包装类都有如下方法(字符串->包装类)

public static Type valueOf(String s)

package javaapidemo0126.demo04;

public class Demo03 {
    /*包装类中常用的方法*/
    public static void main(String[] args) {

        // xxxValue():包装类转换成基本类型
        // Byte byte1 = new Byte("128"); // NumberFormatException 数据格式异常
        Byte byte1 = new Byte("127");
        byte num1 = byte1.byteValue();
        System.out.println("num1 = " + num1); // num1 = 127

        Short short1 = new Short("32767");
        short num2 = short1.shortValue();
        System.out.println("num2 = " + num2); // num2 = 32767

        Integer integer1 = new Integer("2147483647");
        int num3 = integer1.intValue();
        System.out.println("num3 = " + num3); // num3 = 2147483647

        Long long1 = new Long("9223372036854775807");
        // public long longValue()以 long 值的形式返回此 Long 的值
        long num4 = long1.longValue(); // 包装类中对象里的值转换成一个基本数据类型
        System.out.println("num4 = " + num4); // num4 = 9223372036854775807

        Character character1 = new Character('q');
        char num5 = character1.charValue();
        System.out.println("num5 = " + num5); // num5 = q

        Boolean boolean1 = new Boolean("1233");
        Boolean boolean2 = new Boolean("True");
        Boolean boolean3 = new Boolean("true");
        boolean result1 = boolean1.booleanValue();
        boolean result2 = boolean2.booleanValue();
        boolean result3 = boolean3.booleanValue();
        System.out.println("result1 = " + result1); // result1 = false
        System.out.println("result2 = " + result2); // result2 = true
        System.out.println("result3 = " + result3); // result3 = true


        // toString():以字符串形式返回包装对象表示的基本类型数据(基本类型->字符串)
        /*
        * public String toString()返回一个表示该 Integer 值的 String 对象
        * public static String toString(int i)返回一个表示指定整数的 String 对象
        * public static String toString(int i,int radix)返回用第二个参数指定基数表示的第一个参数的字符串表示形式*/
        String str1 = Integer.toString(200); // toString() 静态方法 用Integer类名调用
        System.out.println("str1 : " + str1); // 200是字符串

        String str2 = Character.toString('w');
        System.out.println("str2 : " + str2);

        // parsexxx():把字符串转换为相应的基本数据类型数据(Character除外)(字符串->基本类型)
        byte num6 = Byte.parseByte("123");
        System.out.println("num6 = " + num6);

        // Number类型数据的字符串转换成基本数据类型,字符串需要是数字形式化的字符串,否则不能转换,会报NumberFormatException
        // byte num7 = Byte.parseByte("abc"); // NumberFormatException 数据格式异常
        // System.out.println("num7 = " + num7);

        // Boolean类型数据的字符串转换成基本数据类型时,字符串的值是true(不区分大小写)
        // 结果就是true,其他情况都是false
        boolean bool1 = Boolean.parseBoolean("true");
        System.out.println("bool1 : " + bool1); // true
        boolean bool2 = Boolean.parseBoolean("TruE");
        System.out.println("bool1 : " + bool2); // true
        boolean bool3 = Boolean.parseBoolean("false");
        System.out.println("bool1 : " + bool3); // false
        boolean bool4 = Boolean.parseBoolean("qwer");
        System.out.println("bool1 : " + bool4); // false

        // valueOf():所有包装类都有如下方法(基本类型->包装类)
        Float afloat = Float.valueOf(12.5F);
        System.out.println("afloat : " + afloat); // afloat : 12.5
        Double aDouble = Double.valueOf(12.55);
        System.out.println("aDouble : " + aDouble); // aDouble : 12.55

        // 除Character类外,其他包装类都有如下方法(字符串->包装类)
        Boolean aBoolean = Boolean.valueOf("true");
        System.out.println("aBoolean:" + aBoolean); // aBoolean:true

        Boolean bBoolean = Boolean.valueOf("True");
        System.out.println("bBoolean:" + bBoolean); // bBoolean:true

        Boolean cBoolean = Boolean.valueOf("qwer");
        System.out.println("cBoolean:" + cBoolean); // cBoolean:false

        Boolean dBoolean = Boolean.valueOf("false");
        System.out.println("dBoolean:" + dBoolean); // dBoolean:false

        Short aShort = Short.valueOf("123");
        System.out.println("aShort = " + aShort); // aShort = 123

        Short bShort = Short.valueOf("qwe");
        System.out.println("bShort = " + bShort); // NumberFormatException 报错


    }
}
6、装箱和拆箱

基本类型和包装类的自动转换

装箱:基本类型转换为包装类的对象

拆箱:包装类对象转换为基本类型的值

7、包装类的特点

1)JDK1.5后,允许基本数据类型和包装类型进行混合数学运算

2)包装类并不是用来取代基本数据类型,在基本数据类型需要用对象表示时使用

package javaapidemo0126.demo04;

import com.sun.deploy.net.MessageHeader;

import java.util.ArrayList;

public class Demo04 {

    public static void main(String[] args) {


        int num1 = 100;
        // 装箱:将基本类型的数据或者变量直接赋值给包装类对象
        Integer integer1 = num1;
        System.out.println("integer1 = " + integer1); // integer1 = 100

        Byte byte1 = new Byte("123");
        // 拆箱:将包装类对象直接赋值给基本数据类型的变量
        byte num2 = byte1;
        System.out.println("num2 = " + num2); // num2 = 123

        /*
        * 有了装箱和拆箱的操作,可以对包装类对象和基本数据类型进行算术运算
        * */
        int num3 = 300;
        Integer integer2 = 500;
        int sum1 = num3 + integer2;
        System.out.println("sum1 = " + sum1);

        Integer sum2 = num3 + integer2;
        System.out.println("sum2 = " + sum2);

        /*
        * 集合中不能存储基本数据类型,系统会通过装箱的形式将基本数据类型直接转换为包装类对象*/
        ArrayList arrayList = new ArrayList();
        arrayList.add(100);
        arrayList.add(200);
        arrayList.add(300);

    }
}

四、Math类

1、Math类中静态常量值

java.lang.Math类提供了常用的数学运算方法和两个静态常量E(自然对数的底数) 和PI(圆周率)

package javaapidemo0126.demo05;

public class MathDemo01 {
    public static void main(String[] args) {

        // Math类中的两个静态常量值
        double num1 = Math.E;
        System.out.println("num1 = " + num1); // num1 = 2.718281828459045

        System.out.println(Math.PI); // 3.141592653589793
    }
}
2、Math类中常用方法
package javaapidemo0126.demo05;

public class MathDemo02 {

    public static void main(String[] args) {

        // Math类中常用方法
        // 获取数据绝对值
        System.out.println(Math.abs(100)); // 100
        System.out.println(Math.abs(-100)); // 100

        // 获取两个数据中的最大值
        System.out.println(Math.max(100,200)); // 200
        System.out.println(Math.max(1000,200)); // 1000
        System.out.println(Math.max(100.32,200.55)); // 200.55

        // 获取两个数据中的最小值
        System.out.println(Math.min(100,200)); // 100
        System.out.println(Math.min(1000,200)); // 200
        System.out.println(Math.min(100.32,200.55)); // 100.32

        System.out.println("------ ------ ------");

        // 获取一个数据的近似数
        // 上舍入
        // public static double ceil(double a)返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数
        System.out.println(Math.ceil(3.0)); // 3.0
        System.out.println(Math.ceil(3.1)); // 4.0
        System.out.println(Math.ceil(3.4)); // 4.0
        System.out.println(Math.ceil(3.5)); // 4.0
        System.out.println(Math.ceil(3.6)); // 4.0
        System.out.println(Math.ceil(3.9)); // 4.0

        System.out.println("------ ------ ------");

        // 下舍入
        // public static double floor(double a)返回最大的(最接近正无穷大)double 值,该值小于等于参数,并等于某个整数
        System.out.println(Math.floor(5.0)); // 5.0
        System.out.println(Math.floor(5.1)); // 5.0
        System.out.println(Math.floor(5.4)); // 5.0
        System.out.println(Math.floor(5.5)); // 5.0
        System.out.println(Math.floor(5.6)); // 5.0
        System.out.println(Math.floor(5.9)); // 5.0

        System.out.println("------ ------ ------");

        // 四舍五入
        // public static long round(double a)返回最接近参数的 long
        System.out.println(Math.round(7.0)); // 7
        System.out.println(Math.round(7.1)); // 7
        System.out.println(Math.round(7.4)); // 7
        System.out.println(Math.round(7.5)); // 8
        System.out.println(Math.round(7.6)); // 8
        System.out.println(Math.round(7.9)); // 8

        System.out.println("------ ------ ------");

        // 获取一个数的指定次方结果
        // public static double pow(double a,double b)返回第一个参数的第二个参数次幂的值
        System.out.println(Math.pow(2,10)); // 1024.0
        System.out.println(Math.pow(3,4)); // 81.0

        System.out.println("------ ------ ------");

        // 获取一个数的算术平方根值
        // public static double sqrt(double a)返回正确舍入的 double 值的正平方根
        System.out.println(Math.sqrt(4)); // 2.0
        System.out.println(Math.sqrt(3)); // 1.732
        System.out.println(Math.sqrt(2)); // 1.414

        System.out.println("------ ------ ------");

        // 获取随机数
        // public static double random()返回带正号的 double 值,该值大于等于 0.0 且小于 1.0
        System.out.println(Math.random());
        // Math.random()*10 (0 <= double < 10.0)
        System.out.println(Math.random()*10);
        // (int)(Math.random()*10) 返回一个大于等于0 小于10的int类型的数据
        System.out.println((int)(Math.random()*10));
        // (int)(Math.random()*(num2-num1)+num1)
        // 随即返回一个大于等于num1,且小于num2之间的int类型数据
        int num = (int)(Math.random()*10+10); // [10,20)
        System.out.println("num = " + num);


    }
}

五、Random类

产生随机数的其他方式 java.util.Random

package javaapidemo0126.demo06;

import java.util.Arrays;
import java.util.Random;

public class RandomDemo01 {

    public static void main(String[] args) {

        // java.lang.Math 包中的Math类Random产生随机数
        // java.lang.Object
        // java.util.Random Random类 继承java.lang.Object

        // 使用无参构造方法创建Random类对象
        Random random1 = new Random();

        // 通过random对象调用方法获取随机数
        // public int nextInt()返回下一个伪随机数,它是此随机数生成器的序列中均匀分布的 int 值
        // 所有 2的32次方 个可能 int 值的生成概率(大致)相同
        int num1 = random1.nextInt();
        System.out.println(num1);

        // public int nextInt(int n)返回一个伪随机数
        // 它是取自此随机数生成器序列的、在 0(包括)和指定值(不包括)之间均匀分布的 int 值
        for (int i = 0; i <= 100; i++) {
            int num2 = random1.nextInt(10); // 随机数范围在[0,10)
            System.out.print(num2 + " ");
        }
        System.out.println();

        System.out.println("------ ------ ------");

        // Random类中布尔值
        for (int i = 0; i < 10; i++) {
            boolean bool = random1.nextBoolean();
            System.out.print(bool + " ");
        }
        System.out.println();

        System.out.println("------ ------ ------");

        byte[] bytes = new byte[50];
        random1.nextBytes(bytes);
        System.out.println(Arrays.toString(bytes));

        System.out.println("------ ------ ------");

        /*
        * 用同一个种子值来初始化两个Random 对象,然后用每个对象调用相同的方法,得到的随机数也是相同的
        */
        // 使用有参构造方法创建Random对象
        // public Random(long seed)使用单个 long 种子创建一个新的随机数生成器

        Random r1 = new Random(100L);
        Random r2 = new Random(100L);

        System.out.println(r1.nextInt(50)); // 产生随机数范围[0,50]
        System.out.println(r2.nextInt(50));
        // 产生随机数的结果是一样
        System.out.println(r1.nextBoolean());
        System.out.println(r2.nextBoolean());

        // 注意:要用有参构造方法,传参相同,调用相同的方法则随机数也是相同的,无参构造方法不行

    }
}

六、String类

使用String对象存储字符串

String类位于java.lang包中,具有丰富的方法

计算字符串长度、比较字符串、连接字符串、提取字符串

1、String类构造方法
package javaapidemo0126.demo07;

public class StringDemo01 {

    public static void main(String[] args) {

        /*
        * String str1 = "abc";
        * 等效于
        * char data[] = {'a','b','c'};
        * String str2 = new String(data);*/

        String str1 = "abc";
        System.out.println("str1 : " + str1); // str1:abc

        char data[] = {'a','b','c'};
        String str2 = new String(data);
        System.out.println("str2 : " + str2); // str2:abc

        // 创建String类对象
        String s1 = new String();
        System.out.println("s1 : " + s1);

        byte[] bytes = {97,98,99,100,101,102,103};
        String s2 = new String(bytes);
        System.out.println("s2 : " + s2); // abcdefg

        /*
        * public String(byte[] bytes,int offset,int length)
        * 通过使用平台的默认字符集解码指定的 byte 子数组,构造一个新的 String
        * bytes - 要解码为字符的 byte
        * offset - 要解码的第一个 byte 的索引
        * length - 要解码的 byte 数*/
        String s3 = new String(bytes,1,3);
        System.out.println("s3 : " + s3); // bcd

        System.out.println("------ ------ ------");

        /*
        * public String(char[] value,int offset,int count)
        * 分配一个新的 String,它包含取自字符数组参数一个子数组的字符*/
        char[] chars = {'大','湖','名','城'};
        String s4 = new String(chars);
        System.out.println("s4 : " + s4); // 大湖名城

        String s5 = new String(chars,1,2);
        System.out.println("s5 : " + s5); // 湖名

        System.out.println("------ ------ ------");

        /*public String(String original)初始化一个新创建的 String 对象,使其表示一个与参数相同的字符序列*/

        String s6 = new String("大湖名城,创新高地");
        System.out.println("s6 : " + s6);

        System.out.println("------ ------ ------");

        /*public String(StringBuffer buffer)分配一个新的字符串,它包含字符串缓冲区参数中当前包含的字符序列*/
        /*public String(StringBuilder builder)分配一个新的字符串,它包含字符串生成器参数中当前包含的字符序列*/

        StringBuilder stringBuilder = new StringBuilder("qwertyuiop");
        String s7 = new String(stringBuilder);
        System.out.println("s7 : " + s7);

        // 常用的还是创建String对象,直接传参,public String(String original)
        // 或者简写 String s8 = "abcdefghi";
        
    }
}
2、获取字符串长度
package javaapidemo0126.demo07;

public class StringDemo02 {

    public static void main(String[] args) {

        // 定义一个字符串对象,简写
        String s1 = "qwertyuiopasdfghjklzxcvbnm";

        // 获取字符串长度
        int length = s1.length();
        System.out.println("字符串s1的长度:"+length); // 字符串s1的长度:26

        /*
        * 各种元素长度获取方式:
        *   数组长度:数组名.length;
        *   集合长度:集合名.size();
        *   字符串长度:字符串名.length();
        * */
        // int[] nums = {11,22,33,44,55,66};
        // System.out.println("数组长度为:"+nums.length); // 数组长度为:6


    }
}

练习  

package javaapidemo0126.demo07;

import java.util.Scanner;

public class StringDemo03 {

    public static void main(String[] args) {

        // 注册新用户,要求密码长度不能小于6位

        // 创建Scanner对象
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入用户名:");
        String name = scanner.next();
        System.out.println("请输入密码:");
        String password = scanner.next(); // 注意这里用String类

        while (password.length() < 6) {  // 注意这里用while循环更合适
            System.out.println("密码长度不能小于6位!");
            System.out.println("请输入密码:");
            password = scanner.next();
        }
        System.out.println("注册成功");

    }
}
3、比较字符串内容
package javaapidemo0126.demo07;

public class StringDemo04 {

    public static void main(String[] args) {

        String s1 = "qwert";
        String s2 = "qwert";
        String s3 = "asdfg";
        String s4 = "ASDFG";

        // 比较两个字符串内容是否相同
        // public boolean equals(Object anObject)将此字符串与指定的对象比较
        // equals()方法比较内容时区分大小写
        boolean result1 = s1.equals(s2);
        System.out.println("字符串s1和s2内容一致:" + result1); // true

        boolean result2 = s1.equals(s3);
        System.out.println("字符串s1和s3内容一致:" + result2); // false

        boolean result3 = s3.equals(s4);
        System.out.println("字符串s1和s2内容一致:" + result3); // false // 即区分大小写

        // 比较字符串内容不区分大小写
        // public boolean equalsIgnoreCase(String anotherString)将此 String 与另一个 String 比较,不考虑大小写
        boolean result4 = s3.equalsIgnoreCase(s4);
        System.out.println("不区分大小写比较s3和s4内容一致:" + result4); // true


    }
}
package javaapidemo0126.demo07;

import java.util.Scanner;

public class StringDemo05 {

    public static void main(String[] args) {

        // 需求:从键盘输入用户名和密码实现登录操作
        // 用户名忽略大小写,密码不能忽略大小写,登陆操作只能登录三次,超过三次则不能再登录
        // 假设正确用户名为admin,密码为123ABCabc

        /*String name = "admin";
        String password = "123ABCabc";
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入用户名:");
        String nameInput = sc.next();

        System.out.println("请输入密码:");
        String passwordInput = sc.next();

        boolean quit1 = true;
        while (quit1) {
            if (name.equalsIgnoreCase(nameInput) == false) {
                System.out.println("用户名输入有误!");
                System.out.println("请重新输入:");
                nameInput = sc.next();
            } else {
                quit1 = false;
            }
        }

        boolean quit2 = true;
        int count = 0;
        while (quit2) {
            if (passwordInput.equals(password) == false) {
                System.out.println("密码输入错误,错误三次将无法输入,还剩"+(2-count)+"次机会");
                System.out.println("请重新输入:");
                passwordInput = sc.next();
                count++;
            }else {
                quit2 = false;
            }
            if (count == 2) {
                System.out.println("您已经错误三次无法登录!");
                quit2 = false;
            }
        }*/

        Scanner scanner = new Scanner(System.in);
        String name = "";
        String pwd = "";

        // 定义一个统计变量用来存储用户名和密码的输入次数
        int count = 0;
        do {
            count++;
            if (count > 3) {
                System.out.println("只能输入3次,账号被锁定");
                break;
            }
            System.out.println("请输入用户名:");
            name = scanner.next();
            System.out.println("请输入密码:");
            pwd = scanner.next();
        } while(!(name.equalsIgnoreCase("admin") &&
        pwd.equals("123ABCabc")));

        if (count <= 3) {
            System.out.println("登陆成功!");
        }


    }
}
4、字符串大小转换

 

package javaapidemo0126.demo07;

public class StringDemo06 {

    public static void main(String[] args) {

        //
        String s1 = "qwertQWERT";
        System.out.println("s1 = " + s1);

        // 将字符串s1中内容全部转换为大写 使用toLowerCase()方法
        String lowerCase1 = s1.toLowerCase();
        System.out.println("lowerCase1 = " + lowerCase1); // lowerCase1 = qwertqwert
        System.out.println("s1 = " + s1); // s1 = qwertQWERT

        // 将字符串s1中内容全部转换为小写 使用toUpperCase()方法
        String upperCase1 = s1.toUpperCase();
        System.out.println("upperCase1 = " + upperCase1); // upperCase1 = QWERTQWERT
        System.out.println("s1 = " + s1); // s1 = qwertQWERT

    }
}
5、字符串连接方法

1)使用“+”

2)使用String类的concat()方法

package javaapidemo0126.demo07;

public class StringDemo07 {

    public static void main(String[] args) {

        String s1 = "qwert";
        String s2 = "yuiop";
        String result = s1 + s2;
        System.out.println("字符串s1和s2拼接:" + result); // 字符串s1和s2拼接:qwertyuiop
        System.out.println(s1 + s2);

        // 使用concat()方法连接字符串
        String s3 = s1.concat(s2);
        System.out.println("s3 = " + s3); // s3 = qwertyuiop
        System.out.println("s1 = " + s1); // s1 = qwert
        System.out.println("s2 = " + s2); // s2 = yuiop

        System.out.println("------ ------ ------");

        // 回顾内容
        System.out.println(10 + 20 +"abc"); // 30abc
        System.out.println(10 + "abc" + 20); // 10abc20
        System.out.println("abc" + 10 + 20); // abc1020
        // abc在前与10相加变成字符串,再加20还是字符串
        System.out.println("abc" + (10+20)); // abc30
    }
}
6、字符串提取方法
方法名说明
public char charAt(int index)返回指定索引处的 char 值。索引范围为从 0 到 length() - 1
public int indexOf(int ch)搜索第一个出现的字符ch(或字符串value),如果没有找到,返回-1
public int indexOf(String value)
public int lastIndexOf(int ch)搜索最后一个出现的字符ch(或字符串value),如果没有找到,返回-1
public int lastIndexOf(String value)
public String substring(int index)提取从位置索引开始的字符串部分
public String substring(int beginindex, int endindex)提取beginindex和endindex之间的字符串部分
public String trim()返回一个前后不含任何空格的调用字符串的副本
package javaapidemo0126.demo07;

public class StringDemo08 {

    public static void main(String[] args) {

        // 字符串中常用提取方法

        // public char charAt(int index)返回指定索引处的 char 值。索引范围为从 0 到 length() - 1
        String s1 = "qwert";
        char ch1 = s1.charAt(1);
        System.out.println("ch1 = " + ch1); // w

        System.out.println("------ ------ ------");

        /*
        * int indexOf(int ch)
          返回指定字符在此字符串中第一次出现处的索引
          *
          int indexOf(int ch, int fromIndex)
          返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索
          *
          int indexOf(String str)
          返回指定子字符串在此字符串中第一次出现处的索引
          *
          int indexOf(String str, int fromIndex)
          返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
         */
        String s2 = "qwertqwertsdfghjk";

        // w的ASCII为119
        int index1 = s2.indexOf(119);
        System.out.println("你要查找的w字符第一次出现的位置:" + index1); // 你要查找的w字符第一次出现的位置:1
        int index2 = s2.indexOf('w');
        System.out.println("你要查找的w字符第一次出现的位置:" + index2); // 你要查找的w字符第一次出现的位置:1
        int index3 = s2.indexOf('a');
        System.out.println("你要查找的a字符第一次出现的位置:" + index3); // 你要查找的a字符第一次出现的位置:-1
        // 没有查找到则返回-1

        System.out.println("------ ------ ------");

        int index4 = s2.indexOf(119,4); //
        System.out.println("从指定位置开始查找w字符,第一次出现的位置:" + index4);
        // 从指定位置开始查找w字符,第一次出现的位置:6
        int index5 = s2.indexOf('w',4); //
        System.out.println("从指定位置开始查找w字符,第一次出现的位置:" + index5);
        // 从指定位置开始查找w字符,第一次出现的位置:6

        System.out.println("------ ------ ------");

        // 查找字符串
        int index6 = s2.indexOf("qwe"); // 查找的是子字符串在字符串中第一次出现的索引
        System.out.println("你要查找的字符串在s2中第一次出现的位置:" + index6); // 你要查找的字符串在s2中第一次出现的位置:0
        int index7 = s2.indexOf("qwe",4); //
        System.out.println("从指定位置开始查找字符串在s2中第一次出现的位置:" + index7); // 从指定位置开始查找字符串在s2中第一次出现的位置:5

        int index8 = s2.indexOf("qweqdasd",3);
        System.out.println("从指定位置开始查找字符串在s2中第一次出现的位置:" + index8); // 结果为-1
        // 从指定的索引开始,如果未出现该字符,则返回-1

        System.out.println("------ ------ ------");

        String s3 = "abcqwertqweeyuiopqwe";

        /*
        * int lastIndexOf(int ch)
          返回指定字符在此字符串中最后一次出现处的索引
          *
          int lastIndexOf(int ch, int fromIndex)
          返回指定字符在此字符串中最后一次出现处的索引,从指定的索引处开始进行反向搜索
          *
          int lastIndexOf(String str)
          返回指定子字符串在此字符串中最右边出现处的索引
          *
          int lastIndexOf(String str, int fromIndex)
          返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索
         */

        System.out.println("s3的长度:" + s3.length()); // s3的长度:20

        int index9 = s3.lastIndexOf(119);
        System.out.println("你要查找的字符在s3中最后一次出现的位置:" + index9);
        // 你要查找的字符在s3中最后一次出现的位置:18

        int index10 = s3.lastIndexOf('w');
        System.out.println("你要查找的字符在s3中最后一次出现的位置:" + index10);
        // 你要查找的字符在s3中最后一次出现的位置:18

        int index11 = s3.lastIndexOf('z');
        System.out.println("你要查找的字符在s3中最后一次出现的位置:" + index11);
        // 你要查找的字符在s3中最后一次出现的位置:-1 未出现

        System.out.println("------ ------ ------");

        int index12 = s3.lastIndexOf('w',15);
        System.out.println("从指定索引开始,你要查找的字符在s3中最后一次出现的位置:" + index12);
        // 从指定索引开始,你要查找的字符在s3中最后一次出现的位置:9

        //
        int index13 = s3.lastIndexOf("qwe");
        System.out.println("你要查找的子字符串在s3中最后一次出现的位置:" + index13);
        // 你要查找的子字符串在s3中最后一次出现的位置:17

        int index14 = s3.lastIndexOf("qwe",15);
        System.out.println("从指定位置开始,你要查找的子字符串在s3中最后一次出现的位置:" + index14);
        // 从指定位置开始,你要查找的子字符串在s3中最后一次出现的位置:8
        

    }
}
7、去除字符串首尾空格
package javaapidemo0126.demo07;

public class StringDemo09 {

    public static void main(String[] args) {

        String s1 = "qwertyuiop";

        /*
        * String substring(int beginIndex)
          返回一个新的字符串,它是此字符串的一个子字符串。
          String substring(int beginIndex, int endIndex)
          返回一个新字符串,它是此字符串的一个子字符串
        * */
        String substring1 = s1.substring(3);
        // substring1 注意string是小写
        System.out.println("substring1:" + substring1); // substring1:rtyuiop
        System.out.println("s1:" + s1);

        String substring2 = s1.substring(3,6);
        System.out.println("substring2:" + substring2); // substring2:rty
        System.out.println("s1:" + s1); // 原字符串保持不变

        System.out.println("------ ------ ------");

        /*
        * String trim()
          返回字符串的副本,忽略前导空白和尾部空白 */
        String s3 = "      qwert      yuiop      ";
        String trim = s3.trim();
        System.out.println("trim : " + trim); // trim : qwert      yuiop
        // 去除首尾空白
        System.out.println("s3:" + s3);

        System.out.println("------ ------ ------");

        
    }
}
8、字符串拆分方法
package javaapidemo0126.demo07;

import java.util.Arrays;

public class StringDemo11 {

    public static void main(String[] args) {


        /*
        * String[] split(String regex)
          根据给定正则表达式的匹配拆分此字符串
          String[] split(String regex, int limit)
          根据匹配给定的正则表达式来拆分此字符串
        * */
        // String[] split(String regex):根据给定正则表达式的匹配拆分此字符串
        String s1 = "长亭外 古道边 芳草碧连天 晚风拂 柳笛声残 夕阳山外山";
        String[] strings1 = s1.split(" "); // 遍历数组
        System.out.println(Arrays.toString(strings1));

        String s2 = "长亭外-古道边-芳草碧连天-晚风拂-柳笛声残-夕阳山外山";
        String[] strings2 = s2.split("-");
        System.out.println(Arrays.toString(strings2));

        System.out.println("------ ------ ------");

        // byte[] getBytes():使用平台的默认字符将String编码为byte序列 并将结果存储到一个新的byte数组中
        String s3 = "abcdefg";
        System.out.println("s3:" + s3);
        byte[] bytes = s3.getBytes();
        System.out.println(Arrays.toString(bytes)); // [97, 98, 99, 100, 101, 102, 103]
        System.out.println("s3:" + s3);

        // 遍历bytes数组,输出字符内容
        for (int i = 0; i < bytes.length; i++) {
            System.out.print((char)bytes[i] + " "); // a b c d e f g
        }

        
    }
}
9、判断字符串开头结尾
package javaapidemo0126.demo07;

public class StringDemo12 {

    public static void main(String[] args) {

        //
        // public boolean endsWith(String suffix)测试此字符串是否以指定的后缀结束
        /*
        * boolean startsWith(String prefix)
          测试此字符串是否以指定的前缀开始。
          boolean startsWith(String prefix, int toffset)
          测试此字符串从指定索引开始的子字符串是否以指定前缀开始
        * */

        String s1 = "HelloWorld.java";
        String s2 = "HelloWorld.class";
        String s3 = "WorldHell0World.java";

        boolean result1 = s1.endsWith(".java");
        System.out.println("s1字符串是以.java结尾的:" + result1); // true

        boolean result2 = s2.endsWith(".java");
        System.out.println("s2字符串是以.java结尾的:" + result2); // false

        boolean result3 = s3.startsWith("Hello");
        System.out.println("s3是以Hello开头的:" + result3); // false
        boolean result4 = s3.startsWith("World");
        System.out.println("s3是以world开头的:" + result4); // true

        //

        boolean result5 = s3.startsWith("world",5);
        System.out.println("s3从下标5的地方是以World开头的:" + result5); // false

        boolean result6 = s3.startsWith("World",10);
        System.out.println("s3从下标10的地方是以world开头:" + result6); // true

    }
}
package javaapidemo0126.demo07;

public class StringDemo14 {

    public static void main(String[] args) {

        /*
        * static String copyValueOf(char[] data)
          返回指定数组中表示该字符序列的 String。
          static String copyValueOf(char[] data, int offset, int count)
          返回指定数组中表示该字符序列的 String
*/
        char[] chars = {'大','湖','名','城','创','新','高','地','!'};
        String s2 = String.copyValueOf(chars);
        System.out.println("s2:" + s2); // s2:大湖名城创新高地!

        String s3 = String.copyValueOf(chars,5,4);
        System.out.println("s3:" + s3); // s3:新高地!


    }
}

七、StringBuffer类

1、StringBuffer作用

对字符串频繁修改(如字符串连接)时,使用StringBuffer类可以大大提高程序执行效率

2、声明StringBuffer

StringBuffer strb = new StringBuffer();
StringBuffer strb = new StringBuffer("aaa");

3、StringBuffer的使用

sb.toString();          //转化为String类型
sb.append("**");        //追加字符串
sb.insert (1, "**");    //插入字符串 

4、案例
package javaapidemo0126.demo08;

public class StringBufferDemo01 {

    public static void main(String[] args) {

        // 创建StringBuffer类对象
        /*
        * StringBuffer(String str)
          构造一个字符串缓冲区,并将其内容初始化为指定的字符串内容*/
        StringBuffer stringBuffer1 = new StringBuffer("qwertyuiop");
        System.out.println("stringBuffer1:" + stringBuffer1); // stringBuffer1:qwertyuiop

        StringBuffer stringBuffer2 = stringBuffer1.append(true);
        System.out.println("stringBuffer2:" + stringBuffer2); // stringBuffer2:qwertyuioptrue
        System.out.println("stringBuffer1:" + stringBuffer1); // stringBuffer1:qwertyuioptrue

        StringBuffer stringBuffer3 = stringBuffer2.append(false);
        System.out.println("stringBuffer3: " + stringBuffer3); // stringBuffer3: qwertyuioptruefalse
        System.out.println("stringBuffer2: " + stringBuffer2); // stringBuffer2:qwertyuioptruefalse

        System.out.println("------ ------ ------");

        char[] chars = {'a','b','c','d','e'};
        System.out.println(stringBuffer1.append(chars)); // qwertyuioptruefalseabcde
        System.out.println(stringBuffer1.append(chars,1,3)); // qwertyuioptruefalseabcdebcd

        System.out.println("------ ------ ------");

        StringBuffer stringBuffer4 = new StringBuffer("asdfghjkl");
        System.out.println("stringBuffer4 : " + stringBuffer4); // stringBuffer4 : asdfghjkl

        StringBuffer stringBuffer5 = stringBuffer4.insert(2,"love"); // 也可以插入布尔值
        System.out.println("stringBuffer5 : " + stringBuffer5); // stringBuffer5 : aslovedfghjkl
        System.out.println("stringBuffer4 : " + stringBuffer4); // stringBuffer4 : aslovedfghjkl

        System.out.println(stringBuffer4.insert(7,chars)); // aslovedabcdefghjkl
        System.out.println(stringBuffer4.insert(18,chars,2,3)); // 从下标为多少开始插入 即在下标为多少的位置插入


    }
}
5、练习

将一个数字字符串转换成逗号分隔的数字串,即从右边开始每三个数字用逗号分隔

package javaapidemo0126.demo08;

import java.util.Scanner;

public class StringBufferDemo02 {

    public static void main(String[] args) {

        // 创建键盘录入对象
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串形式的数字:");
        String strNum = scanner.next();

        // 将获取的数据传入到StringBuffer对象中
        StringBuffer stringBuffer = new StringBuffer(strNum);

        // 插入逗号
        for (int i = stringBuffer.length()-3;i >0; i-=3) {
            stringBuffer.insert(i,",");
        }
        System.out.println(stringBuffer);

    }
}
6、String类 & StringBuffer类

String是不可变对象

1)经常改变内容的字符串最好不要使用String

2)StringBuffer是可变的字符串

3)字符串经常改变的情况可使用StringBuffer,更高效

4)JDK5.0后提供了StringBuilder,等价StringBuffer

(StringBuilder一个可变的字符序列。此类提供一个与 StringBuffer 兼容的 API,但不保证同步。该类被设计用作 StringBuffer 的一个简易替换,用在字符串缓冲区被单个线程使用的时候(这种情况很普遍)。如果可能,建议优先采用该类,因为在大多数实现中,它比 StringBuffer 要快。)

八、Date类

package javaapidemo0126.Demo09;

import java.util.Date;

public class DateDemo01 {

    public static void main(String[] args) {

        //使用无参构造方法创建Date对象
        Date date = new Date();
        System.out.println(date);

        //获取年月日、时分秒
        //int getYear() :已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.YEAR) - 1900 取代。
        int year=date.getYear();
        // int getMonth() :已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.MONTH) 取代。返回表示月份的数字,该月份包含或开始于此 Date 对象所表示的瞬间。返回的值在 0 和 11 之间,值 0 表示 1 月。
        int month =date.getMonth();
        //int getDate():已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.DAY_OF_MONTH) 取代。返回此 Date 对象表示的月份中的某一天。返回的值在 1 和 31 之间,表示包含或开始于此 Date 对象表示的时间的月份中的某一天(用本地时区进行解释)。
        int date1 =date.getDate();

        // int getHours() :已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.HOUR_OF_DAY) 取代。
        int hours =date.getHours();
        // int getMinutes():已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.MINUTE) 取代。
        int minutes =date.getMinutes();
        // int getSeconds():已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.SECOND) 取代。
        int seconds =date.getSeconds();

        //获取星期
        // int getDay():已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.DAY_OF_WEEK) 取代。返回此日期表示的周中的某一天。返回值 (0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday) 表示一周中的某一天,该周包含或开始于此 Date 对象所表示的瞬间(用本地时区进行解释)。
        int day=date.getDay();
        //对返回的值进行转换,0转换为星期日,1转换为星期一,2转换为星期二....以此类推
//        String strDay="";
//        switch (day){
//            case 0:
//                strDay = "星期日";
//                break;
//            case 1:
//                strDay = "星期一";
//                break;
//            case 2:
//                strDay = "星期二";
//                break;
//            case 3:
//                strDay = "星期三";
//                break;
//            case 4:
//                strDay = "星期四";
//                break;
//            case 5:
//                strDay = "星期五";
//                break;
//            case 6:
//                strDay = "星期六";
//                break;
//
//        }

        // System.out.println("今天是:"+(year+1900)+"年"+(month+1)+"月"+date1+"日 "+hours+":"+minutes+":"+seconds+" "+strDay);

        // 对于返回的星期数字进行转换,还可以使用数组来做,将返回的代表星期的数字用于数组的下标
        String[] week = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六",};
        System.out.println("今天是:"+(year+1900)+"年"+(month+1)+"月"+date1+"日 "+hours+":"+minutes+":"+seconds+" "+week[day]);
        // 今天是:2024年1月30日 17:21:14 星期二

        // 获取date对象表示的日期时间距离1970年1月1日0:0:0所经历的毫秒数
        long time =date.getTime();
        System.out.println("time:"+time); // time:1706606474640

        long timeMillis =System.currentTimeMillis();
        System.out.println("timeMillis:"+timeMillis); // timeMillis:1706606474664

    }
}
package javaapidemo0126.Demo09;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo02 {

    public static void main(String[] args) {

        // 获取当前系统日期和时间
        Date date = new Date();
        System.out.println(date); // Tue Jan 30 18:46:03 CST 2024

        // 使用无参构造方法创建SimpleDateFormat类对象
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat();

        // 将date格式化成一个文本,需要使用simpleDateFormat对象调用方法实现
        // StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
        // 将给定的 Date 格式化为日期/时间字符串,并将结果添加到给定的 StringBuffer
        String strDate = simpleDateFormat1.format(date);
        System.out.println(strDate); // 24-1-30 下午6:46

        // 使用有参构造方法创建SimpleDateFormat类对象,执行格式化
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss D");
        String strDate2 = simpleDateFormat2.format(date);
        System.out.println(strDate2); // 2024-01-30 18:50:51 30

        /*
        * y 年
        * M 年中的月份
        * d 月份中的天数
        * H 一天中的小时数(0-23)
        * m 小时中的分钟数
        * s 分钟的秒数
        * D 年中的天数
        * */

    }
}
package javaapidemo0126.Demo09;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo03 {

    public static void main(String[] args) throws ParseException {
        /*throws ParseException"是一种声明式异常处理的方式*/

        String s1 = "2024-1-1";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        // 将字符串解析成Date对象
        Date date = simpleDateFormat.parse(s1);
        System.out.println(date); // Mon Jan 01 00:00:00 CST 2024
    }
}
package javaapidemo0126.demo10;

import java.util.Calendar;

public class CalenderDemo01 {

    public static void main(String[] args) {

        // Calendar类是一个抽象类,不能直接通过new的形式创建引用,可以通过多态的形式将其引用指向子类
        // 也可以通过Calendar类中的静态方法获取引用

        // public static Calendar getInstance()使用默认时区和语言环境获得一个日历。
        // 返回的 Calendar 基于当前时间,使用了默认时区和默认语言环境
        Calendar calendar = Calendar.getInstance();
        System.out.println("calendar:" + calendar);

        // int get(int field)返回给定日历字段的值
        // 获取年月日、时分秒
        int year = calendar.get(Calendar.YEAR);
        // MONTH:指示月份的 get 和 set 的字段数字。这是一个特定于日历的值
        // 在格里高利历和罗马儒略历中一年中的第一个月是 JANUARY,它为 0;最后一个月取决于一年中的月份数
        int month = calendar.get(Calendar.MONTH);
        int date = calendar.get(Calendar.DATE);

        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);

        // 获取星期
        int day = calendar.get(Calendar.DAY_OF_WEEK);

        System.out.println("今天是:" + year + "年" + (month + 1) +"月" + date +"日 "
        +hour + ":" + minute + ":" + second + " 星期" + day);

        /*
        * 获取日期和时间
        * java.util.Calendar:这是一个抽象类,提供了操作日期和时间的方法。
        * 它的实例可以通过getInstance()方法获得,然后可以使用各种方法来设置和获取日期和时间的值。
        *
        * java.text.SimpleDateFormat:这是一个用于格式化和解析日期和时间的类。
        * 它可以将日期和时间转换为字符串,也可以将字符串解析为日期和时间。
        * */

    }
}
  • 30
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值