14.方法的定义-练习

This commit is contained in:
2025-12-24 11:58:03 +08:00
parent 1777a20e3c
commit 34f183975c

View File

@@ -24,10 +24,18 @@ public class Demo12_Method {
public static void main(String[] args) { public static void main(String[] args) {
//调用加法功能的方法 //调用加法功能的方法
addMethod(); addMethod();
//调用减法的方法
jfMethod();
} }
//需求定义一个无参无返回值的封装了三元运算符判断i,j哪个变量小的结果并打印sout最后在主方法中调用 //需求定义一个无参无返回值的封装了三元运算符判断i,j哪个变量小的结果并打印sout最后在主方法中调用
public static void jfMethod() {
int a = 20;
int b = 30;
int result = a > b? b:a;
System.out.println(result);
}
//类中方法外 //类中方法外
//需求:将加法的功能封装成一个方法,随时调用 //需求:将加法的功能封装成一个方法,随时调用