java学习笔记-(6) 第7章(下)-面向对象编程(基础部分)

7.4 方法递归调用(非常非常重要,比较难)

7.4.1基本介绍

简单的说: 递归就是方法自己调用自己,每次调用时传入不同的变量.递归有助于编程者解决复杂问题,同时可以让代码变得简洁

7.4.2递归能解决什么问题?

1.各种数学问题如:8皇后问题,汉诺塔,阶乘问题,,迷宫问题,球和篮子的问题(google编程
大赛)[简单演示]
2.各种算法中也会使用到递归,比如快排,归并排序,二分查找,分治算法等.
3.将用栈解决的问题–>递归代码比较简洁

7.4.3递归举例

列举两个小案例,来帮助大家理解递归调用机制

  1. 打印问题
  2. 阶乘问题

代码

public class Recursion01 { 
	public static void main(String[] args) {
  		// 打印问题
		T t1 = new T();
		t1.test(4);//输出什么? n=2 n=3 n=4
		
		// 阶乘问题
		int res = t1.factorial(5); 
		System.out.println("5的阶乘 res =" + res);
	}
}

class T {
	// 打印问题
	public  void test(int n) {
		if (n > 2) {
			test(n - 1);
		} 
		System.out.println("n=" + n);
	}

	//factorial 阶乘
	public  int factorial(int n) {
		if (n == 1) {
			return 1;
		} else {
			return factorial(n - 1) * n;
		}
	}
}

问题1 :打印问题的 内存分析图:
在这里插入图片描述
注意:在哪里调用,就返回哪里。

问题2 :阶乘问题的 内存分析图:
在这里插入图片描述

7.4.4递归重要规则

在这里插入图片描述

7.4.5课堂练习

RecursionExercise01.java

  1. 请使用递归的方式求出斐波那契数1,1,2,3,5,8,13.…给你一个整数n,求出它的值是多少?(提示:后边数是前边两个数的和)。

  2. 猴子吃桃子问题:有一堆桃子,猴子第一天吃了其中的一半,并再多吃了一个!以后
    每天猴子都吃其中的一半,然后再多吃一个。当到第10天时,想再吃时(即还没吃),发现只有1个桃子了。问题:最初共多少个桃子?

问题1 代码:

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

		T t1 = new T();
		int res = t1.fibonacci(7);
		if(res != -1) {
		 	System.out.println("对应的斐波那契数=" + res);
		 } 
	
	}
}

class T {
		/*
		请使用递归的方式求出斐波那契数1,1,2,3,5,8,13...给你一个整数n,求出它的值是多
		思路分析
		1. 当n = 1 斐波那契数 是1
		2. 当n = 2 斐波那契数 是1
		3. 当n >= 3  斐波那契数 是前两个数的和
		4. 这里就是一个递归的思路
		 */
	
		public int fibonacci(int n) {
			if( n >= 1) {
				if( n == 1 || n == 2) {
					return 1;
				} else {
					return fibonacci(n-1) + fibonacci(n-2);
				}
			} else {
				System.out.println("要求输入的n>=1的整数");
				return -1;
			}
		}	
	
}

问题2代码:

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

		T t1 = new T();
		int peachNum = t1.peach(9);
		if(peachNum != -1) {
			System.out.println("有" + peachNum + "个桃子");
		}
	}
}

class T {
		/*
		猴子吃桃子问题:有一堆桃子,猴子第一天吃了其中的一半,并再多吃了一个!
		以后每天猴子都吃其中的一半,然后再多吃一个。当到第10天时,
		想再吃时(即还没吃),发现只有1个桃子了。问题:最初共多少个桃子?
		
		思路分析 逆推
		1. day = 10 时 有 1个桃子
		2. day = 9 时  有 (day10 + 1) * 2 = 4
		3. day = 8 时  有 (day9 + 1) * 2 = 10
		4. 规律就是  前一天的桃子 = (后一天的桃子 + 1) *2//就是我们的能力
		5. 递归
		 */
	public int peach(int day){
		if(day == 10){
			return 1;
		}else if( day >= 1 && day <= 9){
			return (peach(day+1)+1)*2; //day=9,返回(p10+1)*2,
			                           //相当于第9天的等于第10天的加1个再乘2 
		}else{
			System.out.println("dayzai 1-10");
			return -1;
		}
	}	
}

7.4.6递归调用应用实例-迷宫问题

MiGong.java
在这里插入图片描述
代码实现:

public class MiGong { 
	public static void main(String[] args) {
	
		//思路
		//1. 先创建迷宫,用二维数组表示 int[][] map = new int[8][7];
		//2. 先规定 map 数组的元素值: 0 表示可以走 1 表示障碍物 
		
		int[][] map = new int[8][7];
		//3. 将最上面的一行和最下面的一行,全部设置为1
		for(int i = 0; i < 7; i++) {
			map[0][i] = 1;
			map[7][i] = 1;
		}
		//4.将最右面的一列和最左面的一列,全部设置为1
		for(int i = 0; i < 8; i++) {
			map[i][0] = 1;
			map[i][6] = 1;
		}
		map[3][1] = 1;
		map[3][2] = 1;
		map[2][2] = 1; //测试回溯 
		// map[2][1] = 1;
		// map[2][2] = 1;
		// map[1][2] = 1;

		//输出当前的地图
		System.out.println("=====当前地图情况======");
		for(int i = 0; i < map.length; i++) {
			for(int j = 0; j < map[i].length; j++) {
				System.out.print(map[i][j] + " ");//输出一行
			}
			System.out.println();
		}

		//使用findWay给老鼠找路
		T t1 = new T();
		//下右上左
		t1.findWay(map, 1, 1);

		System.out.println("\n====找路的情况如下=====");

		for(int i = 0; i < map.length; i++) {
			for(int j = 0; j < map[i].length; j++) {
				System.out.print(map[i][j] + " ");//输出一行
			}
			System.out.println();
		}
	}
}

class T  {
	//使用递归回溯的思想来解决老鼠出迷宫
	
	//解读
	//1. findWay方法就是专门来找出迷宫的路径
	//2. 如果找到,就返回 true ,否则返回false
	//3. map 就是二维数组,即表示迷宫
	//4. i,j 就是老鼠的位置,初始化的位置为(1,1)
	//5. 因为我们是递归的找路,所以我先规定 map数组的各个值的含义
	//   0 表示可以走 1 表示障碍物 2 表示可以走 3 表示走过,但是走不通是死路
	//6. 当map[6][5] =2 就说明找到通路,就可以结束,否则就继续找.
	//7. 先确定老鼠找路策略 下->右->上->左
	
	public boolean findWay(int[][] map , int i, int j) {
		if(map[6][5] == 2) {//说明已经找到
			return true;
		} else {
			if(map[i][j] == 0) {//当前这个位置0,说明表示可以走
				//我们假定可以走通
				map[i][j] = 2;
				//使用找路策略,来确定该位置是否真的可以走通
				//下->右->上->左
				if(findWay(map, i + 1, j)) {//先走下
					return true;
				} else if(findWay(map, i, j + 1)){//右
					return true;
				} else if(findWay(map, i-1, j)) {//上
					return true;
				} else if(findWay(map, i, j-1)){//左
					return true;
				} else {
					map[i][j] = 3;
					return false;
				}
			} else { //map[i][j] = 1 , 2, 3
				return false; 
			}
		}
	}

	//修改找路策略,看看路径是否有变化
	//下->右->上->左 ==> 上->右->下->左
	public boolean findWay2(int[][] map , int i, int j) {
		if(map[6][5] == 2) {//说明已经找到
			return true;
		} else {
			if(map[i][j] == 0) {//当前这个位置0,说明表示可以走
				//我们假定可以走通
				map[i][j] = 2;
				//使用找路策略,来确定该位置是否真的可以走通
				//上->右->下->左
				if(findWay2(map, i - 1, j)) {//先走上
					return true;
				} else if(findWay2(map, i, j + 1)){//右
					return true;
				} else if(findWay2(map, i+1, j)) {//下
					return true;
				} else if(findWay2(map, i, j-1)){//左
					return true;
				} else {
					map[i][j] = 3;
					return false;
				}
			} else { //map[i][j] = 1 , 2, 3
				return false; 
			}
		}
	}
}

7.4.7递归调用应用实例-汉诺塔

  • 汉诺塔传说
    汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64 片圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。

假如每秒钟移动一次,共需多长时间呢?移完这些金片需要5845.54 亿年以上,太阳系的预期寿命据说也就是数百亿年。真的过了5845.54 亿年,地球上的一切生命,连同梵塔、庙宇等,都早已经灰飞烟灭
在这里插入图片描述

  • 汉诺塔代码实现
    看老师代码演示HanoiTower.java
public class zuoye { 
	public static void main(String[] args) {

		Tower tower = new Tower();
		tower.move(3, 'A', 'B', 'C');
	}
}

class Tower {
	//方法
	//num 表示要移动的个数, a, b, c 分别表示A塔,B 塔, C 塔
	public void move(int num , char a, char b ,char c) {
		//如果只有一个盘 num = 1
		if(num == 1) {
			System.out.println(a + "->" + c);
		} else {
			//如果有多个盘,可以看成两个 , 最下面的和上面的所有盘(num-1)
			//(1)先移动上面所有的盘到 b, 借助 c
			move(num - 1 , a, c, b);
			//(2)把最下面的这个盘,移动到 c
			System.out.println(a + "->" + c);
			//(3)再把 b塔的所有盘,移动到c ,借助a
			move(num - 1, b, a, c);
		}
	}
}

7.4.8递归调用应用实例-八皇后问题

[同学们先尝试做,后面老师评讲.]

  • 八皇后问题说明
    八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例。该问题是国际西洋棋棋手马克斯·贝瑟尔于1848 年提出:在8×8 格的国际象棋上摆放八个皇后,使其不能互相攻击,即:任意两个皇后都不能处于同一行、同一列或同
    一斜线上,问有多少种摆法。
    在这里插入图片描述

7.5 方法重载(OverLoad)

7.5.1基本介绍

java 中允许同一个类中,多个同名方法的存在,但要求形参列表不一致!
比如:System.out.println(); out 是PrintStream 类型
OverLoad01.java

7.5.2重载的好处

  1. 减轻了起名的麻烦
  2. 减轻了记名的麻烦

7.5.3快速入门案例

OverLoad01.java
案例:类:MyCalculator 方法:calculate

  1. calculate(int n1, int n2) //两个整数的和
  2. calculate(int n1, double n2) //一个整数,一个double 的和
  3. calculate(double n2, int n1)//一个double ,一个Int 和
  4. calculate(int n1, int n2,int n3)//三个int 的和

代码

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

		MyCalculator mc = new MyCalculator();
		System.out.println(mc.calculate(1, 2));
		System.out.println(mc.calculate(1.1, 2));
		System.out.println(mc.calculate(1, 2.1));
	}
}

class MyCalculator  {

	//下面的四个 calculate方法构成了重载
	//两个整数的和
	public int calculate(int n1, int n2)  {
		System.out.println("calculate(int n1, int n2) 被调用");
		return n1 + n2;
	}

	//一个整数,一个double的和
	public double calculate(int n1, double n2) {
		return n1 + n2;
	}
	//一个double ,一个Int和 
	public double calculate(double n2, int n1) {
		System.out.println("calculate(double n2, int n1) 被调用..");
		return n1 + n2;
	}
	//三个int的和
	public int calculate(int n1, int n2,int n3) {
		return n1 + n2 + n2;
	}
}

7.5.4注意事项和使用细节

在这里插入图片描述

	public int calculate(int n1, int n2)  {
		System.out.println("calculate(int n1, int n2) 被调用");
		return n1 + n2;
		
	//看看下面是否构成重载, 没有构成,而是方法的重复定义,就错了。a1 a2和n1 n2
	 public int calculate(int a1, int a2)  {
	 	System.out.println("calculate(int n1, int n2) 被调用");
	 	return a1 + a2;
	}
	//以下没有构成方法重载, 仍然是错误的,因为是方法的重复定义
	 public void calculate(int n1, int n2)  {
	 	System.out.println("calculate(int n1, int n2) 被调用");
	 	int res =  n1 + n2;
	 } 
	 

7.5.5课堂练习题

在这里插入图片描述

  • 1.编写程序,类Methods中定义三个重载方法并调用。方法名为m。三个方法分
    别接收一个int参数、两个int参数、一个字符串参数。分别执行平方运算并输出结果,相乘并输出结果,输出字符串信息。在主类的main ( )方法中分别用参数区别调用三个方法。OverLoadExercise.java

  • 2.在Methods类,定义三个重载方法max(),第一个方法,返回两个int值中的最
    大值,第二个方法,返回两个double值中的最大值,第三个方法,返回三个double值中的最大值,并分别调用三个方法。

问题1 代码 方法1(不返回 ,因为没要求返回)


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

		//在主类的main ()方法中分别用参数区别调用三个方法
		Methods method = new Methods();
		method.m(10);//100
		method.m(10, 20);//200
		method.m("韩顺平教育 hello");//字符串信息
	}
}

class Methods {

	//分析
	//1 方法名 m
	//2 形参 (int) 
	//3.void
	public void m(int n) {
		System.out.println("平方=" + (n * n));
	} 

	//1 方法名 m
	//2 形参 (int, int) 
	//3.void
	public void m(int n1, int n2) {
		System.out.println("相乘=" + (n1 * n2));
	}

	//1 方法名 m
	//2 形参 (String) 
	//3.void
	public void m(String str) {
		System.out.println("传入的str=" + str);
	}
}

问题1 代码 方法2(返回)

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

		Methods method = new Methods();
		System.out.println(method.m(10)) ;
		System.out.println(method.m(2,3)) ;
		System.out.println(method.m("ssss")) ;
	}
}

class Methods{
	public int m(int n1){
		return n1 * n1;
	}

	public int m(int n1 , int n2){
		return n1*n2;
	}

	public String m(String str){
		return str;
	}
}

问题2 方法1 比较笨拙

public class zuoye { 
	public static void main(String[] args) {
		
		Methods method = new Methods();
		System.out.println(method.max(24.5,15.6,10.2)) ;
	}
}

class Methods {
	public int max(int n1 , int n2){
		if(n1 > n2){
			return n1;
		}else if(n1 < n2){
			return n2;
		}
		return -1;
	}

	public double max(double n1 , double n2){
		if(n1 > n2){
			return n1;
		}else if(n1 < n2){
			return n2;
		}
		return -1;
	}

	public double max(double n1 , double n2, double n3){
		if(n1 > n2 ){
			if(n1 > n3){
				return n1;
			}else{
				return n3;
			}
			
		}else if( n2 > n1){
			if(n2 > n3){
				return n2;
			}else{
				return n3;
			}
			
		}
		return -1;
	}
}

问题2 方法2 简便


public class zuoye { 
	public static void main(String[] args) {
		
		Methods method = new Methods();
		
		System.out.println(method.max(10, 24)); // 24
		System.out.println(method.max(10.0, 21.4)); // 21.4
		System.out.println(method.max(10.0, 1.4, 30)); // 30.0
	}
}

class Methods {

	public int max(int n1, int n2) {
		return n1 > n2 ? n1 : n2;
	}

	
	public double max(double n1, double n2) {
		return n1 > n2 ? n1 : n2;
	}

	//第三个是double,如果上边输入30 ,也是可以的,int赋给double
	public double max(double n1, double n2, double n3) {
		
		System.out.println("max(double n1, double n2, double n3)");
		//求出n1 和  n2的最大值
		double max1 = n1 > n2 ? n1 : n2;
		return max1 > n3 ? max1 : n3;
	}

	//第三个是int
	public double max(double n1, double n2, int n3) {
		
		System.out.println("max(double n1, double n2, int n3)");
		//求出n1 和  n2的最大值
		double max1 = n1 > n2 ? n1 : n2;
		return max1 > n3 ? max1 : n3;
	}
}

7.6 可变参数

7.6.1基本概念和语法

java 允许将同一个类中多个同名同功能参数个数不同的方法,封装成一个方法。
就可以通过可变参数实现

  • 基本语法
    访问修饰符 返回类型 方法名 (数据类型… 形参名) {
    }

7.6.2快速入门案例(VarParameter01.java)

看一个案例类HspMethod,方法sum 【可以计算2 个数的和,3 个数的和, 4个数的和,5个数的和,6,7,8,9 。。。】

public class VarParameter01 { 
	public static void main(String[] args) {
	
		HspMethod m = new HspMethod();
		System.out.println(m.sum(1, 5, 100)); //106
		System.out.println(m.sum(1,19)); //20
	}
}

class HspMethod {
	//可以计算 2个数的和,3个数的和 , 4. 5, 。。
	//可以使用方法重载
	// public int sum(int n1, int n2) {//2个数的和
	// 	return n1 + n2;
	// }
	// public int sum(int n1, int n2, int n3) {//3个数的和
	// 	return n1 + n2 + n3;
	// }
	// public int sum(int n1, int n2, int n3, int n4) {//4个数的和
	// 	return n1 + n2 + n3 + n4;
	// }
	//.....
	//上面的三个方法名称相同,功能相同, 参数个数不同-> 使用可变参数优化
	//解读
	//1. int... 表示接受的是可变参数,类型是int ,即可以接收多个int(0-多) 
	//2. 使用可变参数时,可以当做数组来使用 即 nums 可以当做数组
	//3. 遍历 nums 求和即可
	public int sum(int... nums) {
		//System.out.println("接收的参数个数=" + nums.length);
		int res = 0;
		for(int i = 0; i < nums.length; i++) {
			res += nums[i];
		}
		return res;
	}
}

7.6.3注意事项和使用细节

在这里插入图片描述
代码

public class VarParameterDetail { 
	public static void main(String[] args) {
		//细节: 可变参数的实参可以为数组
		int[] arr = {1, 2, 3};
		T t1 = new T();
		t1.f1(arr);
	}
}

class T {
	public void f1(int... nums) {
		System.out.println("长度=" + nums.length);
	}
	//细节: 可变参数可以和普通类型的参数一起放在形参列表,但必须保证可变参数在最后
	public void f2(String str, double... nums) {
	
	}
	//细节: 一个形参列表中只能出现一个可变参数
	//下面的写法是错的.
	// public void f3(int... nums1, double... nums2) {
 }
}

7.6.4课堂练习

在这里插入图片描述
代码

public class VarParameterExercise { 
	public static void main(String[] args) {
	
		HspMethod hm = new HspMethod();
		System.out.println(hm.showScore("milan" , 90.1, 80.0 ));
		System.out.println(hm.showScore("terry" , 90.1, 80.0,10,30.5,70 ));
	}
}

class HspMethod  {

	//分析1. 方法名 showScore  2. 形参(String ,double... ) 3. 返回String
	
	public String  showScore(String name ,double... scores ) {

		double totalScore = 0;
		for(int i = 0; i < scores.length; i++) {
			totalScore += scores[i];
		}
		return name + " 有 " +scores.length + "门课的成绩总分为=" + totalScore;
	}
 }

7.7 作用域

7.7.1基本使用

在这里插入图片描述
注意:局部变量:也就是除了属性(全局变量)之外的其他变量,作用域为定义它的代码块中。
代码解释:

public class VarScope { 
	public static void main(String[] args) {
	}
}
class Cat {
	//全局变量:也就是属性,作用域为整个类体 Cat类:cry eat 等方法使用属性
	//属性在定义时,可以直接赋值
	int age = 10; //指定的值是 10

	//全局变量(属性)可以不赋值,直接使用,因为有默认值,
	double weight;  //默认值是0.0

	public void hi() {
		//局部变量必须赋值后,才能使用,因为没有默认值
		int num = 1;
		String address = "北京的猫";
		System.out.println("num=" + num);
		System.out.println("address=" + address);
		System.out.println("weight=" + weight);//属性
	}
	
	public void cry() {
		//1. 局部变量一般是指在成员方法中定义的变量
		//2. n 和  name 就是局部变量
		//3. n 和 name的作用域在 cry方法中
		int n = 10;
		String name = "jack";
		System.out.println("在cry中使用属性 age=" + age);
	}

	public void eat() {
		System.out.println("在eat中使用属性 age=" + age);
		//System.out.println("在eat中使用 cry的变量 name=" + name);//错误
	}
}

7.7.2注意事项和细节使用

VarScopeDetail.java
1.属性和局部变量可以重名,访问时遵循就近原则。

2.在同一个作用域中,比如在同一个成员方法中,两个局部变量,不能重名。[举例]

3.属性生命周期较长,伴随着对象的创建而创建,伴随着对象的销毁而销毁。局部变量,生命周期较短,伴随着它的代码块的执行而创建,伴随着代码块的结束而销毁。即在一次方法调用过程中。

4.作用域范围不同
全局变量/属性:可以被本类使用,或其他类使用(通过对象调用)
局部变量:只能在本类中对应的方法中使用

5.修饰符不同
全局变量/属性 可以加修饰符(public,private,等)
局部变量 不可以加修饰符(public,private,等)

第1,2,3点对应的代码:

public class zuoye { 
	public static void main(String[] args) {
		Person p1 = new Person();
		/*
		属性生命周期较长,伴随着对象的创建而创建,伴随着对象的销毁而销毁。
		局部变量,生命周期较短,伴随着它的代码块的执行而创建,
		伴随着代码块的结束而销毁。即在一次方法调用过程中
		 */
		p1.say();//当执行saAy方法时,say方法的局部变量比如name,会创建,当say执行完毕后
		//name局部变量就销毁,但是属性(全局变量)仍然可以使用
	}
}

class Person {
	//细节: 属性可以加修饰符(public protected private..)
	//      局部变量不能加修饰符
	public int age = 20;
	String name = "jack";

	public void say() {
		//细节 属性和局部变量可以重名,访问时遵循就近原则
		String name = "king";
		System.out.println("say() name=" + name);
	}

	public void hi() {
		String address = "北京";
		//String address = "上海";//错误,重复定义变量
		String name = "hsp";//可以
	}
}

第4点对应代码:第一种

public class VarScopeDetail { 
	public static void main(String[] args) {
		
		T t1 = new T();
		t1.test(); //第1种跨类访问对象属性的方式
	}
}

class T {
	//全局变量/属性:可以被本类使用,或其他类使用(通过对象调用)
	public void test() {
		Person p1 = new Person();
		System.out.println(p1.name);//jack
	}	
}
class Person {
	String name = "jack";
}

第4点代码:第2种跨类访问对象属性的方式

public class VarScopeDetail { 
	public static void main(String[] args) {
		
		Person p1 = new Person();
		T t1 = new T();
		t1.test2(p1);//第2种跨类访问对象属性的方式
	}
}

class T {
	public void test2(Person p) {
		System.out.println(p.name);//jack
	}
}

class Person {
	String name = "jack";	
}

7.8 构造方法/构造器

  • 看一个需求
    我们来看一个需求:前面我们在创建人类的对象时,是先把一个对象创建好后,再给他的年龄和姓名属性赋值,如果现在我要求,在创建人类的对象时,就直接指定这个对象的年龄和姓名,该怎么做? 这时就可以使用构造器。

7.8.1基本介绍和语法

  • 基本介绍
    构造方法又叫构造器(constructor),是类的一种特殊的方法,它的主要作用是完成对新对象的初始化。

它有几个特点:

(1) 方法名和类名相同
(2) 没有返回值
(3) 在创建对象时,系统会自动的调用该类的构造器完成对象的初始化。

  • 基本语法:
    [修饰符] 方法名(形参列表){
    方法体;
    }
  • 说明:
  1. 构造器的修饰符可以默认, 也可以是public protected private
  2. 构造器没有返回值
  3. 方法名和类名字必须一样
  4. 参数列表和成员方法一样的规则
  5. 构造器的调用, 由系统完成

7.8.2 快速入门

现在我们就用构造方法来完成刚才提出的问题:在创建人类的对象时,就直接指定这个对象的年龄和姓名。 Constructor01.java

public class Constructor01 { 
	public static void main(String[] args) {
		//当我们new 一个对象时,直接通过构造器指定名字和年龄
		Person p1 = new Person("smith", 80);
		System.out.println("p1的信息如下");
		System.out.println("p1对象name=" + p1.name);//smith
		System.out.println("p1对象age=" + p1.age);//80
	}
}

//在创建人类的对象时,就直接指定这个对象的年龄和姓名
class Person {
	String name;
	int age;
	//构造器
	//解读
	//1. 构造器没有返回值, 也不能写void
	//2. 构造器的名称和类Person一样
	//3. (String pName, int pAge) 是构造器形参列表,规则和成员方法一样
	public  Person(String pName, int pAge) {
		System.out.println("构造器被调用~~ 完成对象的属性初始化");
		name = pName;
		age = pAge;
	}
}

7.8.3注意事项和使用细节

1.一个类可以定义多个不同的构造器,即构造器重载
比如:我们可以再给Person类定义一个构造器,用来创建对象的时候,只指定人名,不需要指定年龄。

2.构造器名和类名要相同。

3.构造器没有返回值。

4.构造器是完成对象的初始化。并不是创建对象。

5.在创建对象时,系统自动的调用该类的构造方法。

6.如果程序员没有定义构造器,系统会自动给类生成一个默认无参构造器(也
叫默认构造器).比如Dog 00,使用javap指令,反编译看看。

7.一旦定义了自己的构造器,默认的构造器就覆盖了,就不能再使用默认的无
参构造器,除非显式的定义一下,即:Dog00写(这点很重要)

代码:ConstructorDetail.java

public class ConstructorDetail { 
	public static void main(String[] args) {
		Person p1 = new Person("king", 40);//第1个构造器
		Person p2 = new Person("tom");//第2个构造器

		Dog dog1 = new Dog();//使用的是默认的无参构造器
	}
}
class Dog {
	//如果程序员没有定义构造器,系统会自动给类生成一个默认无参构造器(也叫默认构造器)
	//使用javap指令 反编译看看
	/*
		默认构造器
		Dog() {	
		
		}
	 */
	//一旦定义了自己的构造器,默认的构造器就覆盖了,就不能再使用默认的无参构造器,
	//除非显式的定义一下,即:  Dog(){}  写 (这点很重要)
	//
	public Dog(String dName) {
		//...
	}
	Dog() { //显式的定义一下 无参构造器,不写会报错。
	}
}

class Person {
	String name;
	int age;//默认0
	//第1个构造器
	public Person(String pName, int pAge) {
		name = pName;
		age = pAge;
	}
	//第2个构造器, 只指定人名,不需要指定年龄
	public Person(String pName) {
		name = pName;
	}
}

7.8.4 课堂练习题

ConstructorExercise.java
在前面定义的Person 类中添加两个构造器:
第一个无参构造器:利用构造器设置所有人的age 属性初始值都为18
第二个带pName 和pAge 两个参数的构造器:使得每次创建Person 对象的同时初始化对象的age 属性值和name 属性值。分别使用不同的构造器,创建对象.

代码:

public class ConstructorExercise { 
	public static void main(String[] args) {
		
		Person p1 = new Person();//无参构造器
		//下面输出 name = null, age = 18
		System.out.println("p1的信息 name=" + p1.name + " age=" + p1.age);

		Person p2 = new Person("scott", 50);
		//下面输出 name = scott, age = 50
		System.out.println("p2的信息 name=" + p2.name + " age=" + p2.age);
	}
}
class Person {
	String name;//默认值 null
	int age;//默认 0
	
	//第一个无参构造器:利用构造器设置所有人的age属性初始值都为18
	 Person() {
		age = 18;
	}
	//第二个带pName和pAge两个参数的构造器
	public Person(String pName, int pAge) {
		name = pName;
		age = pAge;
	}
}

7.9 对象创建的流程分析

  • 看一个案例
    在这里插入图片描述
    在这里插入图片描述
  • 学习完构造器后,我们类的定义就应该更加完善了
    在这里插入图片描述

7.10 this 关键字

7.10.1 先看一段代码,并分析问题

在这里插入图片描述
在这里插入图片描述
代码:

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

		Dog dog1 = new Dog("大壮", 3);
		System.out.println("dog1的hashcode=" + dog1.hashCode());
		//dog1调用了 info()方法
		dog1.info(); 

		System.out.println("============");
		Dog dog2 = new Dog("大黄", 2);
		System.out.println("dog2的hashcode=" + dog2.hashCode());
		dog2.info();
	}
}

class Dog{ //类

	String name;
	int age;
	// public Dog(String dName, int  dAge){//构造器
	// 	name = dName;
	// 	age = dAge;
	// }
	//如果我们构造器的形参,能够直接写成属性名,就更好了
	//但是出现了一个问题,根据变量的作用域原则
	//构造器的name 是局部变量,而不是属性
	//构造器的age  是局部变量,而不是属性
	//==> 引出this关键字来解决
	public Dog(String name, int  age){//构造器
		//this.name 就是当前对象的属性name
		this.name = name;
		//this.age 就是当前对象的属性age
		this.age = age;
		System.out.println("this.hashCode=" + this.hashCode());
	}

	public void info(){//成员方法,输出属性x信息
		System.out.println("this.hashCode=" + this.hashCode());
		System.out.println(name + "\t" + age + "\t");
	}
}

7.10.2 深入理解this

为了进一步理解this,我们再看一个案例(This01.java)
在这里插入图片描述
在这里插入图片描述

7.10.3 this 的注意事项和使用细节

  1. this 关键字可以用来访问本类的属性、方法、构造器

  2. this 用于区分当前类的属性和局部变量

  3. 访问成员方法的语法:this.方法名(参数列表);

  4. 访问构造器语法:this(参数列表); 注意只能在构造器中使用(即只能在构造器中访问另外一个构造器, 必须放在第一条语句)

  5. this 不能在类定义的外部使用,只能在类定义的方法中使用。

代码:ThisDetail.java

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

		// T t1 = new T();
		// t1.f2();
		T t2 = new T();
		t2.f3();

	}
}

class T {

	String name = "jack";
	int num = 100;

	/*
	细节: 访问构造器语法:this(参数列表); 
	注意只能在构造器中使用(即只能在构造器中访问另外一个构造器)

	注意: 访问构造器语法:this(参数列表); 必须放置第一条语句 
	 */
	
	public T() {
		//这里去访问 T(String name, int age) 构造器
		this("jack", 100);
		System.out.println("T() 构造器");	
	}

	public T(String name, int age) {
		System.out.println("T(String name, int age) 构造器");
	}

	//this关键字可以用来访问本类的属性
	public void f3() {
		String name = "smith";
		//传统方式
		System.out.println("name=" + name + " num=" + num);//smith  100
		//也可以使用this访问属性
		System.out.println("name=" + this.name + " num=" + this.num);//jack 100
	}
	//细节: 访问成员方法的语法:this.方法名(参数列表);
	public void f1() {
		System.out.println("f1() 方法..");
	}

	public void f2() {
		System.out.println("f2() 方法..");
		//调用本类的 f1
		//第一种方式
		f1();
		//第二种方式
		this.f1();
	}	
}

7.10.4 this 的课堂案例

定义Person 类,里面有name、age 属性,并提供compareTo 比较方法,用于判断是否和另一个人相等,提供测试类TestPerson 用于测试, 名字和年龄完全一样,就返回true, 否则返回false。
代码:TestPerson.java


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

		Person p1 = new Person("mary", 20);
		Person p2 = new Person("mary", 20);

		System.out.println("p1和p2比较的结果=" + p1.compareTo(p2));
		//p1是当前值,this.name
	}
}

class Person {
	String name;
	int age;
	//构造器
	public Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	//compareTo比较方法
	public boolean compareTo(Person p) {
		//名字和年龄完全一样
		// if(this.name.equals(p.name) && this.age == p.age) {
		// 	return true;
		// } else {
		// 	return false;
		// }
		return this.name.equals(p.name) && this.age == p.age;
		//this.name代表当前对象的name  p.name是传进来的值。
			}
}

7.11 本章作业

在这里插入图片描述
第1题代码:

public class Homework01 { 
	public static void main(String[] args) {
	
		A01 a01 = new A01();
		double[] arr = {1, 1.4, -1.3, 89.8, 123.8 , 66}; //;{};
		Double res = a01.max(arr);
		if(res != null) {
			System.out.println("arr的最大值=" + res);
		} else {
			System.out.println("arr的输入有误, 数组不能为null, 或者{}");
		}
	}
}
/*
编写类A01,定义方法max,实现求某个double数组的最大值,并返回

思路分析
1. 类名 A01
2. 方法名 max
3. 形参 (double[])
4. 返回值 double

先完成正常业务,然后再考虑代码健壮性
 */
class A01 {
	public Double max(double[] arr) {
		//先判断arr是否为null,然后再判断 length 是否>0
		if( arr!= null && arr.length > 0 ) {

			//保证arr至少有一个元素 
			double max = arr[0];//假定第一个元素就是最大值
			for(int i = 1; i < arr.length; i++) {
				if(max < arr[i]) {
					max = arr[i];
				}
			}
			return max;//double
		} else {
			return null; //返回0不行,返回0.0也不行,最大值有可能是0.0
		}
	}
}

第2题代码:

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

		String[] strs = {"jack", "tom", "mary","milan"};
		A02 a02 = new A02();
		int index = a02.find("milan", strs);
		System.out.println("查找的index=" + index);
	}
}

//编写类A02,定义方法find,实现查找某字符串是否在字符串数组中,
//并返回索引,如果找不到,返回-1
//分析
//1. 类名 A02
//2. 方法名 find
//3. 返回值 int
//4. 形参 (String , String[])
//
//自己补充代码健壮性
class A02 {

	public int find(String findStr, String[] strs) {
		//直接遍历字符串数组,如果找到,则返回索引
		for(int i = 0; i < strs.length; i++) {
			if(findStr.equals(strs[i])) {
				return i;
			}
		}
		//如果没有,就返回-1
		return -1;
	}
}

第3题代码:方法1 较简单

public class zuoye { 
	public static void main(String[] args) {
	
		Book b = new Book();
		b.updatePrice("高数",200);
	}
}

class Book {
	public void updatePrice(String name, double price){
		if(price > 150){
			price = 150 ;
		}else if (price > 100){
			price = 100;
		}
		System.out.println("书名为:" + name +  "价格为:" + price);
	}
}

第3题代码:方法2 较综合

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

		//测试
		Book book = new Book("笑傲江湖", 300);
		book.info();
		book.updatePrice();//更新价格
		book.info();
	}
}
/*
编写类Book,  定义方法updatePrice,实现更改某本书的价格,
具体:如果价格>150,则更改为150,如果价格>100,更改为100,否则不变

分析
1. 类名 Book
2. 属性 price, name
3. 方法名 updatePrice
4. 形参 ()
5. 返回值 void
6. 提供一个构造器
 */

class Book {
	String name;
	double price;
	public Book(String name, double price) {
		this.name = name;
		this.price = price;
	}
	public void updatePrice() {
		//如果方法中,没有 price 局部变量, this.price 等价 price
		if(price > 150) {
			price = 150;
		} else if(price > 100 ) {
			price = 100;
		} 
	}

	//显示书籍情况
	public void info() {
		System.out.println("书名=" + this.name + " 价格=" + this.price);
	}
}

在这里插入图片描述
第4题代码:

public class Homework04 { 
	public static void main(String[] args) {
		
		int[] oldArr = {10, 30, 50};
		A03 a03 = new A03();
		int[] newArr = a03.copyArr(oldArr);
		//遍历newArr,验证
		System.out.println("==返回的newArr元素情况==");
		for(int i = 0; i < newArr.length; i++) {
			System.out.print(newArr[i] + "\t");
		}
	}
}

/*
编写类A03, 实现数组的复制功能copyArr,输入旧数组,返回一个新数组,元素和旧数组一样
 */
class A03 {
	public int[] copyArr(int[] oldArr) {
		//在堆中,创建一个长度为 oldArr.length 数组
		int[] newArr = new int[oldArr.length];
		//遍历 oldArr,将元素拷贝到 newArr
		for(int i = 0; i < oldArr.length; i++) {
			newArr[i] = oldArr[i];
		}
		return newArr;
	}
}

第5题代码,方法1 ,没用到属性

public class zuoye { 
	public static void main(String[] args) {
	
	Circle c = new Circle();
	c.zhouchang(5.0);
	c.mianji(5.0);
	}
}

class Circle {

	double radius; //没用到

	public void zhouchang(double banjing){
		System.out.println(2.0 * Math.PI * banjing);
	}

	public void mianji(double banjing){
		System.out.println( Math.PI * banjing * banjing);
	}
}

第5题代码,方法2

public class Homework05 { 
	public static void main(String[] args) {
	
		Circle circle = new Circle(3);
		System.out.println("面积=" + circle.area());
		System.out.println("周长=" + circle.len());
	}
}
/*
定义一个圆类Circle, 定义属性:半径,提供显示圆周长功能的方法, 提供显示圆面积的方法
 */
class Circle {
	double radius;

	public Circle(double radius) {
		this.radius = radius;
	}

	public double area() { //面积
		return Math.PI * radius * radius;
	}

	public double len() { //周长
		return 2 * Math.PI * radius;
	}
}

第6题代码:

public class Homework06 { 
	public static void main(String[] args) {
	
		Cale cale = new Cale(2, 10);
		System.out.println("和=" + cale.sum());
		System.out.println("差=" + cale.minus());
		System.out.println("乘=" + cale.mul());
		
		Double divRes = cale.div();
		if(divRes != null) {
			System.out.println("除=" + divRes);
		} 
	}
}

/*
 编程创建一个Cale计算类,在其中定义2个变量表示两个操作数,
 定义四个方法实现求和、差、乘、商(要求除数为0的话,要提示) 并创建两个对象,分别测试 
 */

class Cale {
	double num1;
	double num2;
	public Cale(double num1, double num2) {
		this.num1 = num1;
		this.num2 = num2;
	}
	//和
	public double sum() {
		return num1 + num2;
	}
	//差
	public double minus() {
		return num1 - num2;
	}
	//乘积
	public double mul() {
		return num1 * num2;
	}
	//除法
	//
	public Double div() {
		//判断
		if(num2 == 0) {
			System.out.println("num2 不能为0");
			return null;
		} else {
			return num1 / num2;
		}
	}
}

在这里插入图片描述

第7题代码:

public class zuoye { 
	public static void main(String[] args) {
	
	Dog d = new Dog("xiaof","红色",2);
	d.show();
	}
}

class Dog {

	String name;
	String color;
	int age;
	
	public Dog (String name ,String color, int age){
		this.name = name;
		this.color =color;
		this.age = age;
	}
	
	public void show(){
		System.out.println("姓名为:" + name + "颜色为:" + color + "年龄为:" + age);
	} 
}

第8题代码和分析:重要
在这里插入图片描述
在这里插入图片描述
第9题代码:

public class Homework09 { 
	public static void main(String[] args) {
	
		Music music = new Music("笑傲江湖", 300);
		music.play();
		System.out.println(music.getInfo());
	}
}
/*
义Music类,里面有音乐名name、音乐时长times属性,
并有播放play功能和返回本身属性信息的功能方法getInfo
 */
class Music {
	String name;
	int times;
	public Music(String name, int times) {
		this.name = name;
		this.times = times;
	}
	//播放play功能
	public void play() {
		System.out.println("音乐 " + name + " 正在播放中.... 时长为" + times + "秒");
	}
	//返回本身属性信息的功能方法getInfo
	public String getInfo() {
		return "音乐 " + name + " 播放时间为" + times;
	}
}

第10题分析:
在这里插入图片描述
在这里插入图片描述
第11题不太懂。

第12题代码:

public class Homework12 { 
	public static void main(String[] args) {
	}
}
/*
创建一个Employee类, 
属性有(名字,性,别年龄,职位,薪水), 提供3个构造方法,可以初始化  
(1) (名字,性别,年龄,职位,薪水), 
(2) (名字,性别,年龄) (3) (职位,薪水), 要求充分复用构造器  
 */
class Employee {
	//名字,性别,年龄,职位,薪水
	String name;
	char gender;
	int age;
	String job;
	double sal;
	//因为要求可以复用构造器,因此先写属性少的构造器
	
	//职位,薪水
	public Employee(String job, double sal) {
		this.job = job;
		this.sal = sal;
	}
	
	//名字,性别,年龄
	public Employee(String name, char gender, int age) {
		this.name = name;
		this.gender = gender;
		this.age = age;
	}
	
	//名字,性别,年龄,职位,薪水
	public Employee(String job, double sal, String name, char gender, int age) {
		this(name, gender, age);//使用到 前面的 构造器
		this.job = job;//this语句必须放在构造器的第一句,所以2 3 句不能再复用了
		this.sal = sal;//this语句必须放在构造器的第一句,所以2 3 句不能再复用了
	}
}

在这里插入图片描述
第13题代码:第13题不太懂。

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

		Circle c = new Circle();
		PassObject po = new PassObject();
		po.printAreas(c, 5);
	}
}
/*
题目要求:
(1) 定义一个Circle类,包含一个double型的radius属性代表圆的半径,findArea()方法返回圆的面积。
(2) 定义一个类PassObject,在类中定义一个方法printAreas(),该方法的定义如下:
     public void printAreas(Circle c, int times) 	//方法签名/声明
(3) 在printAreas方法中打印输出1到times之间的每个整数半径值,以及对应的面积。例如,times为5,则输出半径1,2,3,4,5,以及对应的圆面积。
(4) 在main方法中调用printAreas()方法,调用完毕后输出当前半径值。程序运行结果如图所示

 */
class Circle { //类
	double radius;//半径
	public Circle() { //无参构造器

	}
	public Circle(double radius) {
		this.radius = radius;
	}
	public double findArea() {//返回面积
		return Math.PI * radius * radius;
	}   
	//添加方法setRadius, 修改对象的半径值
	public void setRadius(double radius) {
		this.radius = radius;
	}
}
class PassObject {
	public void printAreas(Circle c, int times) {
		System.out.println("radius\tarea");
		for(int i = 1; i <= times; i++) {//输出1到times之间的每个整数半径值
			c.setRadius(i) ; //修改c 对象的半径值
			System.out.println((double)i + "\t" + c.findArea());
		}
	}
}

在这里插入图片描述
第14题代码:没大看懂,了解下

import java.util.Random;                                                                              
import java.util.Scanner;                                                                             
                                                                                                      
/*                                                                                                    
请编写一个猜拳的游戏                                                                                            
有个人 Tom,设计他的成员变量. 成员方法, 可以电脑猜拳. 电脑每次都会随机生成 0, 1, 2                                                    
0 表示 石头 1 表示剪刀 2 表示 布                                                                                 
并要可以显示 Tom的输赢次数(清单), 假定 玩三次.                                                                          
 */ 
 // 测试类,主类
public class MoraGame {                                                                               
                                                                                                      
    // 测试                                                                                             
    public static void main(String[] args) {                                                          
        // 创建一个玩家对象                                                                                   
        Tom t = new Tom();                                                                            
        // 用来记录最后输赢的次数                                                                                
        int isWinCount = 0;                                                                           
                                                                                                      
        // 创建一个二维数组,用来接收局数,Tom出拳情况以及电脑出拳情况                                                            
        int[][] arr1 = new int[3][3];                                                                 
        int j = 0;                                                                                    
                                                                                                      
        // 创建一个一维数组,用来接收输赢情况                                                                          
        String[] arr2 = new String[3];                                                                
                                                                                                      
        Scanner scanner = new Scanner(System.in);                                                     
        for (int i = 0; i < 3; i++) {   //比赛3次                                                              
            // 获取玩家出的拳                                                                                
            System.out.println("请输入你要出的拳(0-拳头,1-剪刀,2-布):");                                           
            int num = scanner.nextInt();                                                              
            t.setTomGuessNum(num);                                                                    
            int tomGuess = t.getTomGuessNum();                                                        
            arr1[i][j + 1] = tomGuess;                                                                
                                                                                                      
            // 获取电脑出的拳                                                                                
            int comGuess = t.computerNum();                                                           
            arr1[i][j + 2] = comGuess;                                                                
                                                                                                      
            // 将玩家猜的拳与电脑做比较                                                                           
            String isWin = t.vsComputer();                                                            
            arr2[i] = isWin;                                                                          
            arr1[i][j] = t.count;                                                                     
                                                                                                      
            // 对每一局的情况进行输出                                                                            
           System.out.println("=========================================");                           
            System.out.println("局数\t玩家的出拳\t电脑的出拳\t输赢情况");                                             
            System.out.println(t.count + "\t" + tomGuess + "\t\t" + comGuess + "\t\t" + t.vsComputer());
            System.out.println("=========================================");                          
            System.out.println("\n\n");                                                               
            isWinCount = t.winCount(isWin);                                                           
        }                                                                                             
                                                                                                      
        // 对游戏的最终结果进行输出                                                                               
        System.out.println("局数\t玩家的出拳\t电脑的出拳\t\t输赢情况");                                               
        for (int a = 0; a < arr1.length; a++) {                                                       
            for (int b = 0; b < arr1[a].length; b++) {                                                
                System.out.print(arr1[a][b] + "\t\t\t");                                              
            }                                                                                         
                                                                                                      
            System.out.print(arr2[a]);                                                                
            System.out.println();                                                                     
        }                                                                                             
        System.out.println("你赢了" + isWinCount + "次");                                                 
    }                                                                                                 
                                                                                                      
}                                                                                                     

// Tom类
class Tom {     // 核心代码  
	// 玩家出拳的类型 
    int tomGuessNum; //0,1,2
	// 电脑出拳的类型
    int comGuessNum; //0,1,2
	// 玩家赢的次数
    int winCountNum;  
	// 比赛的次数
    int count = 1;   //一共比赛3次                                                                                 
     
	
	public void showInfo() {
		//....
	}
	
    /**                                                                                               
     * 电脑随机生成猜拳的数字的方法                                                                                 
     * @return                                                                                        
     */                                                                                               
    public int computerNum() {                                                                        
        Random r = new Random();                                                                      
        comGuessNum = r.nextInt(3);      // 方法 返回 0-2的随机数                                                             
        // System.out.println(comGuessNum);                                                           
        return comGuessNum;                                                                           
    }                                                                                                 
                                                                                                      
    /**                                                                                               
     * 设置玩家猜拳的数字的方法                                                                                   
     * @param tomGuessNum                                                                             
     */                                                                                               
    public void setTomGuessNum(int tomGuessNum) {                                                     
        if (tomGuessNum > 2 || tomGuessNum < 0) { 
			//抛出一个异常, 李同学会写,没有处理
            throw new IllegalArgumentException("数字输入错误");                                             
        }                                                                                             
        this.tomGuessNum = tomGuessNum;                                                               
    }                                                                                                 
                                                                                                      
    public int getTomGuessNum() {                                                                     
        return tomGuessNum;                                                                           
    }                                                                                                 
                                                                                                      
    /**                                                                                               
     * 比较猜拳的结果                                                                                        
     * @return 玩家赢返回true,否则返回false                                                                    
     */                                                                                               
    public String vsComputer() { 
		 //比较巧
        if (tomGuessNum == 0 && comGuessNum == 1) {                                                   
            return "你赢了";                                                                             
        } else if (tomGuessNum == 1 && comGuessNum == 2) {                                            
            return "你赢了";                                                                             
        } else if (tomGuessNum == 2 && comGuessNum == 0) {                                            
            return "你赢了";                                                                             
        } else if (tomGuessNum == comGuessNum){                                                       
            return "平手";                                                                              
        } else {                                                                                      
            return "你输了";                                                                             
        }                                                                                             
    }                                                                                                 
                                                                                                      
    /**                                                                                               
     * 记录玩家赢的次数                                                                                       
     * @return                                                                                        
     */                                                                                               
    public int winCount(String s) {                                                                   
        count++;    //控制玩的次数                                                                                   
        if (s.equals("你赢了")) {     //统计赢的次数                                                                   
            winCountNum++;                                                                            
        }                                                                                             
        return winCountNum;                                                                           
    }                                                                                                 
                                                                                                      
}                                                                                                     
                                                                                                      
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农小C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值