package com;
public class Demo {
public static void main(String[] args) {
// 无参数无返回值的方法调用
test();
// 无参数有返回值的方法调用
String str1 = test1();
System.out.println(str1);
System.out.println("----------------");
// 有参数有返回值的方法调用
String str2 = test2("有参数有返回值的方法");
System.out.println(str2);
System.out.println("----------------");
// 有参数有返回值的方法调用
int max = getMax(20, 10);
System.out.println("最大值"+max);
// 有参数无返回值的方法调用
test3("这是");
};
/**
* 无参数无返回值
* public 访问权限
* static 静态方法
* void 有无返回值
* 方法名 后面括号定义参数
* 格式 public static void 方法名()
*/
public static void test() {
System.out.println("无参数无返回值的方法");
System.out.println("----------------");
};
/**
* 无参数有返回值
* 格式 public static 返回值类型 方法名()
* @return
*/
public static String test1() {
String str= "无参数有返回值";
return str;
};
/**
* 有参数有返回值
* 格式 public static 返回值类型 方法名(参数1,...)
*/
public static String test2(String f ) {
return f;
};
/**
* 有参数有返回值
* 格式 public static 返回值类型 方法名(参数1,参数2,....)
*/
public static int getMax(int a, int b) {
if (a>b) {
return a;
} else {
return b;
}
};
/**
* 有参数无返回值
* public static void 方法名(参数1,...)
*/
public static void test3(String str3) {
System.out.println(str3+"有参数无返回值");
};
};