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;i>0;i--){
for (int j=0; j 0;o--){
System.out.print("*");
}
System.out.print("
");
}
}
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;i>0;i--){
for(int n=i;n0;i--)
{
for(int j=0;j System.out.print("*");
System.out.print("
");
}
}
}
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;i>0;i--)
{
for(int j=i;j>1;j--){
System.out.print(" ");}
for(int n=i;n0;i--){
for(int n=0;n System.out.print("*");
}
for(int j=i;j0;i--){
for(int f=0;f0;i--){
for(int j=i;j0;n--){ /*n=10;n>0;循环一次,打印一个 * ,在执行n--,
*此时n=9;n>0;再循环一次,再打印一个 * ,在执行n--,
*此时n=8;n>0;再循环一次,再打印一个 * ,在执行n--,
*依次类推... 所就在第一行打印了10个 * 。
*接下来执行 System.out.print("
"); 换行 。
*然后执行第一个大循环中的 i-- ; 此时 i 就等于 9 了。
*
*这时 第一个小循环 中:(j=i 从 i=9 开始循环)
*j=9;j0;循环一次,打印一个 * ,在执行n--,
*此时n=8;n>0;再循环一次,再打印一个 * ,在执行n--,
*依次类推... 所就在第二行打印了 9 个 * 。
*接下来执行 System.out.print("
"); 换行 。
*然后执行第一个大循环中的 i-- ; 此时 i 就等于 8 了。
*
*往下 依次类推....
*/
System.out.print("*");
}
System.out.print("
");
}
}
}
登录后复制
以上就是详解for循环的Java小程序的详细内容,更多请关注米云其它相关文章!
