2004年8月22日 六个主要是 for 循环的小程序

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 < 10-i; j++) {

                  System.out.print(" ");
                }

         for(int o=i;o>0;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;i>0;i--){  
         for(int n=i;n<11;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;i>0;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;i>0;i--)
  {
   for(int j=i;j>1;j--){
       System.out.print(" ");}
   
   for(int n=i;n<11;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;i>0;i--){
   
   for(int n=0;n
    System.out.print("*");
    }
   
   for(int j=i;j<11;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;i>0;i--){
   for(int f=0;f<10;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;i>0;i--){
   for(int j=i;j<11;j++){ //j=10;j<11;循环一次,打印一个 0 ,在执行 j++ ,
                                   //此时j=11;i<11;为false,所以在第一行只打印了一个 0 。
   System.out.print("0");}
   for(int n=i;n>0;n--){ /*n=10;n>0;循环一次,打印一个 * ,在执行n--,
                         *此时n=9;n>0;再循环一次,再打印一个 * ,在执行n--,
                         *此时n=8;n>0;再循环一次,再打印一个 * ,在执行n--,
                         *依次类推... 所就在第一行打印了10个 * 。
                         *接下来执行 System.out.print("/n"); 换行 。
                         *然后执行第一个大循环中的 i-- ; 此时 i 就等于 9 了。
                         *
                         *这时 第一个小循环 中:(j=i 从 i=9 开始循环)
                         *j=9;j<11;循环两次,所以在第二行只打印 2 个 0 。
                         *这时 第二个小循环 中:(n=i 从 i=9 开始循环)
                         *n=9;n>0;循环一次,打印一个 * ,在执行n--,
                         *此时n=8;n>0;再循环一次,再打印一个 * ,在执行n--,
                         *依次类推... 所就在第二行打印了 9 个 * 。
                         *接下来执行 System.out.print("/n"); 换行 。
                         *然后执行第一个大循环中的 i-- ; 此时 i 就等于 8 了。
                         *
                         *往下 依次类推....
                      */
    System.out.print("*");
   }
  
  System.out.print("/n");
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值