标签:
package day06; //方法的演示 public class MethodDemo { public static void main(String[] args) { //say(); //sayHi(); //编译错误,必须传参数 //sayHi(8); //编译错误,参数类型不匹配 //sayHi("zhangsan"); //String name="zhangsan" //sayHi("lisi"); //String name="lisi" //sayHi("wangwu"); //String name="wangwu" //int num = getNum(); //System.out.println(num); //88 //double d = plus(5,6); //double num1=5,double num2=6 //System.out.println(d); //11 //double a = 5.5; //double b = 4.4; //double dou = plus(a,b); //double num1=5.5,double num2=4.4 //System.out.println(dou); a(); //方法的嵌套调用 System.out.println("over"); } public static void a(){ System.out.println(111); b(); System.out.println(222); } public static void b(){ System.out.println(333); c(); } public static void c(){ System.out.println(444); } //有参有返回值 public static double plus(double num1,double num2){ //double num = num1+num2; //return num; //返回的不是num,而是num里面那个数 return num1+num2; //返回的是num1+num2的值 } //无参有返回值 public static int getNum(){ //return; //编译错误,必须返回一个值 //return 5.55; //编译错误,返回值类型不匹配 return 88; //1.结束方法的执行 2.返回结果(250)给调用方 } //有参无返回值 public static void sayHi(String name){ System.out.println("大家好,我叫"+name); return; //1.结束方法的执行 } //无参无返回值 public static void say(){ System.out.println("大家好,我叫WKJ"); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u011637069/article/details/47322043