package com.method;
public class Demo01 {
//main方法
public static void main(String[] args) {
int sum = add(1,2);
System.out.println(sum);
}
//加法
public static int add(int a ,int b){
return a+b;
}
}
package com.method;
public class Demo02 {
//main方法
public static void main(String[] args) {
test();
}
//测试方法
public static void test(){
for (int i = 0;i<= 1000;i++){
if (i%5==0){
System.out.print(i+"\t");
}
if (i%15==0){
System.out.println();
}
}
}
}
3方法-比大小
package com.method;
public class Demo03 {
public static void main(String[] args) {
int max = max(10,20);
System.out.println(max);
}
//比大小
public static int max(int num1,int num2) {
int resoult = 0;
if (num1 == num2) {
System.out.println("num1==num2");
return 0;
}
if (num1 > num2) {
resoult = num1;
} else {
resoult = num2;
}
return resoult;
}
}
4-方法-递归
package com.method;
public class Demo04 {
public static void main(String[] args) {
System.out.println(f(4));
}
//递归方法
public static int f(int n){
if(n==1){
return 1;
}else {
return n*f(n-1);
}
}
}
原文:https://www.cnblogs.com/guanglongedu/p/14843686.html