说明
案例1
案例2
案例3
案例4
案例5
案例6
package lesson.l11_oop2;/*** Illustration** @author DengQing* @version 1.0* @datetime 2022/7/2 21:24* @function 将对象作为参数传递给方法*/
public class Circle {double radius;public double findArea() {return Math.PI * Math.pow(radius, 2);}}class PassObject {public void printAreas(Circle c, int time) {System.out.println("Radius\t\tArea");for (int i = 1; i <= time; i++) {c.radius = i;System.out.println(c.radius + "\t\t" + c.findArea());}c.radius = time + 1;}public static void main(String[] args) {PassObject passObject = new PassObject();Circle c = new Circle();passObject.printAreas(c, 5);System.out.println("now radius is " + c.radius);}
}
代码
package lesson.l10_oop;import java.util.Arrays;/*** Illustration** @author DengQing* @version 1.0* @datetime 2022/7/1 17:44* @function 值传递机制*/
public class ValueTransfer {public static void main(String[] args) {int[] arr = new int[]{1, 6, -3, 0, 10, 3, 5};ValueTransfer valueTransfer = new ValueTransfer();valueTransfer.print(arr);valueTransfer.bubbleSort(arr);valueTransfer.print(arr);}/*** @return void* @Author DengQing* @Date 2022/7/1 17:47* @Param [arr]* @Function 数组的冒泡排序*/public void bubbleSort(int[] arr) {for (int i = 0; i < arr.length - 1; i++) {for (int j = 0; j < arr.length - 1 - i; j++) {if (arr[j] > arr[j + 1]) {swap(arr, j, j + 1);}}}}/*** @return void* @Author DengQing* @Date 2022/7/1 17:47* @Param [arr, i, j]* @Function 交换数组的两个数*/public void swap(int[] arr, int i, int j) {int temp = arr[j];arr[j] = arr[i];arr[i] = temp;}/*** @return void* @Author DengQing* @Date 2022/7/1 17:48* @Param [arr]* @Function 打印数组*/public void print(int[] arr) {System.out.println(Arrays.toString(arr));}
}