【备战蓝桥杯第6天】复习方法相关…
来源:互联网 发布:网络上的男人 编辑:程序博客网 时间:2024/04/30 09:49
调用方法
public class MythodDemo1 {
public static void main(Stringargs[]){
print();
print();
}
public static void print(){
System.out.print("Hello,World!");
}
}
定义有返回值的方法
public class MythodDemo2 {
public static void main(String args[]){
System.out.println(add(10,20));
}
public static int add(int x,int y){//定义加法 要有返回值
int temp=x+y;
return temp; //计算结果返回
}
}
方法重载
public class MythodDemo3{
public static void main(String args[]){
System.out.println(add(10,20));
System.out.println(add(10,20,30));
}
public static int add(int x,int y){//定义加法 要有返回值
int temp=x+y;
return temp; //计算结果返回
}
public static float add(float x,float y){//定义加法 要有返回值
float temp=x + y;
return temp; //计算结果返回
}
public static int add(int x,int y,int z){//定义加法 要有返回值
int temp=x+y+z;
return temp; //计算结果返回
}
return用来结束当前方法
public class MythodDemo6 {
public static void main(String args[]){
fun(10);
fun(3);
}
public static void fun(int x){
System.out.println("进入方法");
if(x==3){
return ; //返回方法的被调用出,结束当前方法
}
System.out.println("结束方法");
}
}
*************************************递归算法***********************************************
public class MythodDemo6 { //方法重载,方法名相同,参数类型不同或个数不同
public static void main(String args[]){
fun(10);
fun(3);
}
public static void fun(int x){
System.out.println("进入方法");
if(x==3){
return ; //返回方法的被调用出,结束当前方法
}
System.out.println("结束方法");
}
}
0 0
- 【备战蓝桥杯第6天】复习方法相关…
- 【备战蓝桥杯第6天】复习数组相关…
- 【备战蓝桥杯第6天】复习-方法调用…
- 【备战蓝桥杯第4天】2015-12-13--&…
- 【备战蓝桥杯第5天】2015年12月16…
- 【备战蓝桥杯第7天】复习面向对象…
- 备战
- 备战
- 数学复习方法
- 申论复习方法
- 计算机专业的复习方法
- 清华大学期末复习方法
- 备战软考(6) 2014年度下半年软考备战分析报告
- 2007GCT考试备考复习方法
- 四六级考试复习方法谈
- 新GRE数学四大复习方法
- 60天备战省赛1——生成函数
- 【备战蓝桥杯第一日】2015年12月12…
- 12-4 plsql中使用循环语句
- 【备战蓝桥杯第一日】2015年12月12…
- 【备战蓝桥杯第4天】2015-12-13--&…
- 【备战蓝桥杯第5天】2015年12月16…
- 【备战蓝桥杯第6天】复习数组相关…
- 【备战蓝桥杯第6天】复习方法相关…
- 【备战蓝桥杯第6天】复习-方法调用…
- 【备战蓝桥杯第7天】复习面向对象…
- 【蓝桥杯】2015年12月31日 关于
- 2016年1月16日 关于String类的学习
- 2016年1月16日 关于String类…
- 2016年1月16日 关于String类…
- C语言排序方法
- 2016年1月18日 String练习题