Java函数的学习

来源:互联网 发布:广联达软件客服电话 编辑:程序博客网 时间:2024/06/09 20:41
/*** 方法是一段能完成独立功能的代码块。我们只需要写一次,可以被多次调用,提高了代码的复用性!*函数又叫方法**返回值类型[void]:就是函数执行后要给调用者的数据类型。如果指定了,就必须要有return,如果是void就可以不指定return。*/class  Demo1{ /***主函数是一个指挥者*/public static void main(String[] args) {int a = 19;int b =30;//主函数调用方法int result = compareNum(a,b);System.out.println(result);}/***方法是真正的执行者*/public static int compareNum(int a,int b){//定义变量int result = 0;if(a > b){result = a;}else if(a<b){result = b;}//返回结果return result;}}

0 0
原创粉丝点击