day02-方法的概述
This commit is contained in:
24
day02/src/com/inmind/method03/Demo13.java
Normal file
24
day02/src/com/inmind/method03/Demo13.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.inmind.method03;
|
||||
/*
|
||||
方法:就是将对应的java语句封装成单独的一个功能
|
||||
作用:当我们需要这个功能的时候,就可以去调用。这样即实现了代码的复用性,也解决了代码冗余的现象。
|
||||
注意:
|
||||
1.不调用不执行
|
||||
2.方法必须定义在类中方法外,方法中不能再定义方法
|
||||
*/
|
||||
public class Demo13 {
|
||||
public static void main(String[] args) {
|
||||
//调用加法功能方法
|
||||
getSum();
|
||||
}
|
||||
|
||||
|
||||
//方法的抽取
|
||||
public static void getSum() {
|
||||
//加法运算
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
int sum = a+b;
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user