day04-方法_定义注意事项
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.inmind.method;
|
||||
/*
|
||||
学习方法的注意事项
|
||||
1.方法要定义在类中方法外
|
||||
2.当方法的返回值类型为void的时候,需要写return?不需要。
|
||||
可以写return?可以,但是return之后不能跟任何数据,只能写return;
|
||||
3.return:结束方法,跟是否返回方法的调用处无关,只要方法结束了一定返回方法调用处
|
||||
4.在一个方法中可以写多个return吗?
|
||||
可以,但是只能有一个return被调用
|
||||
*/
|
||||
public class Demo03 {
|
||||
public static void main(String[] args) {
|
||||
int a = 0;
|
||||
if (a > 10) {
|
||||
return;
|
||||
} else if (a > 3 && a <= 10) {
|
||||
System.out.println("a的值在3~10之间");
|
||||
return;
|
||||
} else {
|
||||
System.out.println("a的值小于等于3");
|
||||
}
|
||||
|
||||
System.out.println("程序结束");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user