Files
javaSE260715/day02/src/com/inmind/method03/Demo13.java
2026-07-16 11:51:50 +08:00

41 lines
1.3 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.method03;
/*
方法:就是将对应的java语句封装成单独的一个功能
作用:当我们需要这个功能的时候,就可以去调用。这样即实现了代码的复用性,也解决了代码冗余的现象。
注意:
1.不调用不执行
2.方法必须定义在类中方法外,方法中不能再定义方法
------------------------------------------------------------------
该类方法定义格式照抄main方法即可
格式:
方法修饰符 返回值类型 方法名()
{
}
格式分析:
1.方法修饰符public static (固定,照抄)
2.返回值类型方法的返回值的数据类型void表示没有返回值类型固定照抄void
3.方法名:标识符中的一种,符合软性规范:符合小驼峰命名方式 methodHelloWord
4.():方法参数参数可以写0或多个固定什么都不写没有参数
5.{java代码}方法体就是java语句的集合也就是方法被调用后要执行的java代码
*/
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);
}
}