14.方法的定义-练习
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
//类中方法外
|
//类中方法外
|
||||||
//需求:将加法的功能封装成一个方法,随时调用
|
//需求:将加法的功能封装成一个方法,随时调用
|
||||||
|
|||||||
Reference in New Issue
Block a user