Java_无参数无返回类型方法及练习

无参数无返回类型方法语法格式:

        public static void 方法名称(){
          方法体;
        }

 1 class Method03{
 2     /*练习3:输出1-100中的每个数,要求使用无参无返回类型的方法完成
 3     无参数无返回类型 语法格式:
 4     public static void 方法名称(){
 5         方法体
 6     }
 7     */
 8     public static void print(){
 9         for(int i = 1; i <= 100; i++){
10             System.out.println(i);
11         }
12     }
13 }
14 class Method04{
15     public static void main(String[ ]args){
16         Method03.print();        //调用Method03
17     }
18 }

猜你喜欢

转载自www.cnblogs.com/penphy/p/10747309.html