方法入门

 1 /*
 2 定义一个方法的格式:
 3 public static void 方法名称() {
 4     方法体
 5 }
 6 
 7 方法名称的命名规则和变量一样,使用小驼峰。
 8 方法体:也就是大括号当中可以包含任意条语句。
 9 
10 注意事项:
11 1. 方法定义的先后顺序无所谓。
12 2. 方法的定义不能产生嵌套包含关系。
13 3. 方法定义好了之后,不会执行的。如果要想执行,一定要进行方法的【调用】。
14 
15 如何调用方法,格式:
16 
17 方法名称();
18 */
19 public class Demo11Method {
20     
21     public static void main(String[] args) {
22         farmer(); // 调用农民的方法
23         seller(); // 调用小商贩的方法
24         cook(); // 调用厨子的方法
25         me(); // 调用我自己的方法
26     }
27     
28     // 厨子
29     public static void cook() {
30         System.out.println("洗菜");
31         System.out.println("切菜");
32         System.out.println("炒菜");
33         System.out.println("装盘");
34     }
35     
36     //
37     public static void me() {
38         System.out.println("吃");
39     }
40     
41     // 小商贩
42     public static void seller() {
43         System.out.println("运输到农贸市场");
44         System.out.println("抬高价格");
45         System.out.println("吆喝");
46         System.out.println("卖给厨子");
47     }
48     
49     // 农民伯伯
50     public static void farmer() {
51         System.out.println("播种");
52         System.out.println("浇水");
53         System.out.println("施肥");
54         System.out.println("除虫");
55         System.out.println("收割");
56         System.out.println("卖给小商贩");
57     }
58 }

 

posted @ 2020-09-23 09:36  Oooooooa  阅读(78)  评论(0)    收藏  举报