六个for循环的Java小程序源码展播

王朝java/jsp·作者佚名  2008-05-31
宽屏版  字体: |||超大  

1、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是运行结果:

**********

*********

********

*******

******

*****

****

***

**

*

*/

public class XingHaoOne {

public static void main(String[] args) {

for(int i=10;i0;i--){

for (int j=0; j

System.out.print(" ");

}

for(int o=i;o0;o--){

System.out.print("*");

}

System.out.print("\n");

}

}

2、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是打印结果:

*

**

***

****

*****

******

*******

********

*********

**********

*/

public class XingHaoTwo {

public static void main(String[] args) {

for(int i=10;i0;i--){

for(int n=i;n

System.out.print("*");

}

System.out.print("\n");

}

}

}

3、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是运行结果:

**********

*********

********

*******

******

*****

****

***

**

*

*/

public class XingHaoThree {

public static void main(String[] args) {

for(int i=10;i0;i--)

{

for(int j=0;j System.out.print("*");

System.out.print("\n");

}

}

}

4、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是打印结果:

*

**

***

****

*****

******

*******

********

*********

**********

*/

public class XingHaoFour {

public static void main(String[] args) {

for(int i=10;i0;i--)

{

for(int j=i;j1;j--){

System.out.print(" ");}

for(int n=i;n

System.out.print("*");

}

System.out.print("\n");

}

}

}

5、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是运行结果:

***********

***********

***********

***********

***********

***********

***********

***********

***********

***********

*/

public class XingHaoJuXing {

public static void main(String[] args) {

for(int i=10;i0;i--){

for(int n=0;nSystem.out.print("*");

}

for(int j=i;j

System.out.print("*");

}

System.out.print("\n");

}

}

}

6、

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是打印结果:

**********

**********

**********

**********

**********

**********

**********

**********

**********

**********

*/

public class Shishi {

public static void main(String[] args) {

for(int i=10;i0;i--){

for(int f=0;f

System.out.print("*");}

System.out.print("\n");

}

}

}

再来个带 注释 的 :

/*

* Created on 2004-8-22

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author diyer6

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/*

此图是打印结果:

0**********

00*********

000********

0000*******

00000******

000000*****

0000000****

00000000***

000000000**

0000000000*

*/

public class Zaishi {

public static void main(String[] args) {

for(int i=10;i0;i--){

for(int j=i;j

//此时j=11;i

System.out.print("0");}

for(int n=i;n0;n--){ /*n=10;n0;循环一次,打印一个 * ,在执行n--,

*此时n=9;n0;再循环一次,再打印一个 * ,在执行n--,

*此时n=8;n0;再循环一次,再打印一个 * ,在执行n--,

*依次类推... 所就在第一行打印了10个 * 。

*接下来执行 System.out.print("\n"); 换行 。

*然后执行第一个大循环中的 i-- ; 此时 i 就等于 9 了。

*

*这时 第一个小循环 中:(j=i 从 i=9 开始循环)

*j=9;j

*这时 第二个小循环 中:(n=i 从 i=9 开始循环)

*n=9;n0;循环一次,打印一个 * ,在执行n--,

*此时n=8;n0;再循环一次,再打印一个 * ,在执行n--,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有