<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>循环语句相关文章列表 | 皇家元林</title>
	<atom:link href="https://hjyl.org/tags/%e5%be%aa%e7%8e%af%e8%af%ad%e5%8f%a5/feed/" rel="self" type="application/rss+xml" />
	<link>https://hjyl.org</link>
	<description>刘元林的个人博客</description>
	<lastBuildDate>Mon, 14 Nov 2011 15:18:21 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://img.hjyl.org/uploads/2019/10/cropped-about-me-32x32.png</url>
	<title>循环语句相关文章列表 | 皇家元林</title>
	<link>https://hjyl.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Java-函数</title>
		<link>https://hjyl.org/java-functions/</link>
					<comments>https://hjyl.org/java-functions/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Mon, 14 Nov 2011 15:18:21 +0000</pubDate>
				<category><![CDATA[元林手札]]></category>
		<category><![CDATA[break]]></category>
		<category><![CDATA[continue]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[函数]]></category>
		<category><![CDATA[循环语句]]></category>
		<category><![CDATA[重载]]></category>
		<guid isPermaLink="false">http://hjyl.org/?p=2047</guid>

					<description><![CDATA[简单介绍下循环语句的break和continue命令；详细介绍并举例函数的格式用法；然后介绍函数重载的情况；]]></description>
										<content:encoded><![CDATA[<p>在说函数之前，简单说下循环语句的其他控制语句——break（跳出）和continue（继续）。</p>
<p>break：应用于选择结构和循环结构；</p>
<p>continue：仅应用于循环结构；</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;华&#8212;&#8211;丽&#8212;&#8211;的&#8212;&#8211;分&#8212;&#8211;割&#8212;&#8211;线&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>函数：指定义在类中的具有特殊功能的独立小程序；</p>
<pre lang="java" line="1">
格式：修饰符 返回值类型 函数名(参数类型 形式参数1, 参数类型 形式参数2, ...)
{
        执行语句;
        return 返回值;
}
</pre>
<p>返回值类型：函数运行后的结果的数据类型；<br />
参数类型：形式参数的数据类型；<br />
形式参数：是一个变量，用于存储调用函数时传递给函数的参数；<br />
return用于结束函数；<br />
返回值：返回给调用者；</p>
<p>此函数的功能用法类似于WordPress的函数，就是有些代码直接甩进functions.php，然后在其他文件直接调用，函数就这么简单，只是Java代码不一样。举俩例打印矩形和打印99乘法表：</p>
<pre lang="java" line="1">
class Function
{
	public static void main(String[] args)
	{
		draw(14, 15);  //直接调用下面打印4*5矩形的函数
		print99();   //调用打印99乘法表
		//System.out.println("Hello Java");
	}

	/*
	1、打印矩形；
	定义两个参数行row、列col
	*/
	public static void draw(int row, int col)
	{
		for(int x=0; x<row; x++)
		{
			for(int y=0; y<col; y++)
			{
				System.out.print("*");  //打印*号
			}
			System.out.println();  //换行；
		}
	}

	/*
	2、打印99乘法表
	*/
	public static void print99()
	{
		for(int x=0; x<=9; x++)
		{
			for(int y=0; y<=x; y++)
			{
				System.out.print(y+"*"+x+"="+y*x+"t");
			}
		System.out.println();
		}

	}
}
</pre>
<p>虽然我懂函数的格式，但是你叫我写函数，写不出来，这些都是教程里的例子，只是为了说明格式的用法；</p>
<p>然后说函数的重载：在同一个类中，允许存在两个以上的同名函数，只要他们的参数个数或参数类型不同即可；举例：</p>
<pre lang="java" line="1">
class Function
{
	public static void main(String[] args)
	{
		System.out.println("x+y="+add(4,8));
		System.out.println("x+y+z="+add(4, 8, 9));
	}

	//一个加法运算，获取两个整数的和
	public static int add(int x, int y)
	{
		return x+y;
	}

	//一个加法运算，获取三个整数的和
	public static int add(int x, int y, int z)
	{
		return x+y+z;
	}
}
</pre>
<p>O了！真正的函数不仅要知道这些简单的结构，更关键的还是要知道怎么去定义变量，怎么运算。慢慢折腾吧！太他妈困了，每次看教程，就跟一群瞌睡虫在耳边转，不晕都不行啊！困觉吧！</p>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="Java-函数" href="https://hjyl.org/java-functions/">Java-函数</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/java-functions/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
			</item>
		<item>
		<title>循环语句for和while</title>
		<link>https://hjyl.org/for-while-java/</link>
					<comments>https://hjyl.org/for-while-java/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Wed, 09 Nov 2011 15:24:59 +0000</pubDate>
				<category><![CDATA[元林手札]]></category>
		<category><![CDATA[do while]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[while]]></category>
		<category><![CDATA[循环语句]]></category>
		<guid isPermaLink="false">http://hjyl.org/?p=2037</guid>

					<description><![CDATA[循环语句for和while介绍和实例]]></description>
										<content:encoded><![CDATA[<p>首先介绍下语法：</p>
<pre lang="java" line="1">
//while 语句语法：（while 先判断条件，只有满足条件才执行语句；）
while(条件表达式)
{
	执行语句;
}

//do while 语句语法：（do while 特点是无论条件是否满足，循环体至少被执行一次。）
do
{
	执行语句;
}
while(条件表达式);

//for 语句语法：
for(初始化变量; 条件表达式 ; 循环后操作表达式)
{
	执行语句;
}
</pre>
<p>这三个循环语句都差不多，while 与 do while的区别如上括弧里所述；while与for的区别在于，for语句中，用于控制循环的增量定义在for内，变量只在for语句内有效，for语句执行完毕，则变量在内存中释放，而while的变量会一直在内存里。for与while可以互换，当如果定义增量在循环语句内，则用for。</p>
<p>简单实例：</p>
<pre lang="java" line="1">
class WhileFor
{
	public static void main(String[] args)
	{
		int x=0;
		while(x<5)
		{
			System.out.println("陈冠希-Blow Jobs"); //这句while 含义就是 定义x=0，当x<5的时候，打印“显示陈冠希n次！”这时候只能ctrl+C停止；
		}


		int x=0;
		do
		{
			System.out.println("陈冠希-Blow Jobs"); //跟while一样的效果
		}
		while(x<5);

		int x=0;
		do
		{
			System.out.println("陈冠希-Blow Jobs 显示"+x+++"次"); //这样就只显示5次
		}
		while(x<5);

		for(int x=0; x<5; x++)
		{
			System.out.println("陈冠希-Blow Jobs"); //显示“陈冠希-Blow Jobs” 5次
		}
	}

</pre>
<p>这些简单，看例子就知道怎么用了！<br />
知识点：无限循环最简单的表现形式：</p>
<pre lang="java" line="1">
for(;;){}
while(true){}
</pre>
<p>接着看点复杂点的，嵌套语句：</p>
<pre lang="java" line="1">
/*
实例：1~100中7的倍数的个数，并打印显示；

思路：
	1、先对1~100进行循环（遍历）的形式表示出来；
	2、在遍历中定义条件，只对7的倍数进行操作；
	3、因为7的倍数不确定，只要符合条件，定义一个变量记录这个变化的次数；

步骤：
	1、定义循环语句，选择for语句；
	2、在循环中定义判断，使用if语句，条件：7的倍数：x%7==0;
	3、定义一个变量，随7的倍数出现而递增；

*/

class WhileIf
{
	public static void main(String[] args)
	{
		int count=0;
		for(int x=1; x<=100; x++)
		{
			if(x%7==0)
				//System.out.println("x="+x); //这段代码是打印所有7的倍数；
				count++;
		}
		System.out.println("7的倍数有"+count+++"个"); //计数7的倍数有多少个；
	}
}
</pre>
<p>比嵌套语句还要复杂点的，就是循环中还要循环：<br />
经典实例——99乘法表：</p>
<pre lang="java" line="1">
/*
九九乘法表
1*1=1
1*2=2 2*2=4
1*3=3 3*2=6 3*3=9
.......
*/

class ForFor
{
	public static void main(String[] args)
	{
		for(int x=1; x<=9; x++)
		{
			for(int y=1; y<=x; y++)
			{
				System.out.print(y+"*"+x+"="+y*x+"t"); //注意这里没有换行；
			}
			System.out.println(); //换行；
		}
	}
}
</pre>
<p>好了，第五节课结束！NND，每次看教程看的我只想睡觉。。。只有做笔记的时候还算清醒点，不说了，困觉去。。。</p>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="循环语句for和while" href="https://hjyl.org/for-while-java/">循环语句for和while</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/for-while-java/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
