Java_方法的调用①及案例

方法调用的语法格式:

      类名.方法名称([参数列表]);

调用过程:

 案例:

 1 class Method01{
 2     /*练习1:使用方法完成,输出5遍HelloWorld
 3        方法语法格式:
 4        [修饰符]  返回值类型  方法名称([参数列表]){
 5             方法体
 6         }
 7 
 8         *******注意:1.方法编写在类中
 9                             2.用户自定义的方法,并不会自动执行,则必须进行方法的调用
10     */
11     public static void print(){
12         for(int i = 1; i <= 5;i++){
13             System.out.println("第"+ i +"遍HelloWorld!");
14         }
15     }
16     public static void main(String[ ]args){
17         System.out.println("OK");
18         //调用Method01种的print方法,语法格式:类名.方法名称([参数列表]);
19         Method01.print();
20     }
21 }
原文地址:https://www.cnblogs.com/penphy/p/10709918.html