## 方法
![image-20221231214246351](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231214246351.png)
![image-20221231221749988](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231221749988.png)
![image-20221231223950596](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231223950596.png)
***Java都是值传递***
![image-20221231225736690](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231225736690.png)
![image-20221231232617038](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231232617038.png)
![image-20221231234351882](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20221231234351882.png)
![image-20230101160724236](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20230101160724236.png)
能不用递归就不用递归
![image-20230101163822769](C:\Users\biao\AppData\Roaming\Typora\typora-user-images\image-20230101163822769.png)
package com.fang.method;
public class Demo01 {
//main方法
public static void main(String[] args) {
//实际参数:实际调用传递给他的参数
int sum = add(1,2);
System.out.println(sum);
int sum2 = add(1,2,3);
System.out.println(sum2);
double sum3 = add(1.1,2.1);
System.out.println(sum3);
double sum4 = add(1.1,1.1);
System.out.println(sum4);
double sum5 = add(2.1,4.8);
System.out.println(sum5);
}
//加法
//形式参数,用来定义作用的
public static int add(int a,int b){
return a+b;
}
public static int add(int a,int b,int c){
return a+b+c;
}
public static double add(double a,double b){
return a+b;
}
public static int add(int a,double b){
return (int)(a+b);
}
public static int add(double a,int b) {
return (int) (a + b);
}
}
package com.fang.method;
public class Demo02 {
public static void main(String[] args) {
int a = max(10,10);
System.out.println(a);
int c = min(80,80);
System.out.println(c);
}
//比大小
public static int max(int num1,int num2){
int result = 0;
if(num1==num2){
System.out.println("num1==num2");
return 0;//终止方法
}
if(num1>num2){
result = num1;
}else{
result = num2;
}
return result;
}
public static int min(int a,int b){
int result=-1;
if(a==b){
System.out.println("两个数相等");
return 000;
}
if (a>b){
result = b;
}else{
result = a;
}
return result;
}
}
package com.fang.method;
public class Demo03 {
public static void main(String[] args) {
//args.length 数组长度
for (int i = 0; i < args.length; i++) {
System.out.println("args["+i+"]:"+args[i]);
}
}
}
package com.fang.method;
public class Demo04 {
public static void main(String[] args) {
// 调用可变参数的方法
Demo04 demo04 = new Demo04();
demo04.test(1,2,3,5);
printMax(1,2,3);
printMax(new double[]{3.3,2.2,1.1});//new double 啥意思
}
public void test(int ... i){
System.out.println(i[3]);
}
public static void printMax(double... numbers){
if (numbers.length == 0){
System.out.println("No argument passed");
return;
}
double result = numbers[0];
for (int i = 1;i< numbers.length;i++){
if (numbers[i]>result){
result = numbers[i];
}
}
System.out.println("The max value is "+ result);
}
}
package com.fang.method;
public class Demo05 {
public static void main(String[] args) {
Demo05 test = new Demo05();
test.test();
}
public void test(){
test();
}
}
package com.fang.method;标签:int,image,System,day14,static,println,public From: https://www.cnblogs.com/biao3/p/17018265.html
public class Demo06 {
//递归思想
public static void main(String[] args) {
System.out.println(f(6));
}
//阶乘
//1! 1
//2! 2*1
//3! 3*2*1
public static int f(int n){
if (n==1){
return 1;
}else{
return n*f(n-1);
}
}
}