一、理解
目前代码存在的问题:冗余1.降低代码的可读性
System . out . println ("好好学习"):
for ( int i = l : i <=30; i ++)(
System . out . print ("-");
2.降低代码的可维护性
System . out . println ();
System . out . println ("天天向上"):
for ( int i = l ; i <=30;1++)(
System . out . print ("-");
解决的思路:
}
1.重复的代码写一遍,起名字
System . out . println ();
2.通过名字进行反复的使用
System . out . println (" good good
for ( int i = l ;1<=30;1++)(
System . out . print ("-");
System . out . println ();
函数:执行一段特定功能的代码,可以通过
名字被反复的使用
System . out . println (" day day up ");
1.函数:执行一段特定功能的代码,并且可以通过名字被反复的调用
2.函数的使用流程:
(1)函数的定义:确定了函数的功能和函数名
a .函数的声明:确定函数名
b .函数的实现:确定函数功能
(2)函数的调用:通过函数名进行反复的使用
3.函数定义的位置:定义在类以内,其他函数以外(与 main 并列)
函数的理解
最新推荐文章于 2024-07-27 13:31:57 发布