Files
javaSE251223/day04/src/com/inmind/Demo02_method_notification.java

40 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind;
/*
学习方法的注意事项
1.方法要定义在类中方法外
2.当方法的返回值类型为void的时候需要写return不需要。
可以写return可以,但是return之后不能跟任何数据只能写return;
3.return:结束方法,跟是否返回方法的调用处无关,只要方法结束了一定返回方法调用处
4.在一个方法中可以写多个return吗
可以但是只能有一个return被调用
*/
public class Demo02_method_notification {
public static void main(String[] args) {
if (5 > 3) {
System.out.println("1");
return;
}
if (2 > 3) {
System.out.println("2");
return;
}
if (4 > 3) {
System.out.println("3");
return;
}
printHW(5);
System.out.println("程序结束");
}
//方法练习3_打印n遍HelloWorld
public static void printHW(int n){
for (int i = 0; i < n; i++) {
System.out.println("helloworld");
}
}
}