A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© DengLl 中级黑马   /  2015-3-9 08:47  /  993 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

   上一篇的九九乘法表是用do...while循环语句实现的,据大神说"如果int i=9;   int n=9;   没有必要共享数据给其他方法,就最好定义在方法里面,那么就可以不浪费内存,所以建议使用for遍历!"

    这是我用for循环做的九九乘法表
//for 循环的九九乘法表
/*作者 DengLl
名称:九九乘法表
*/
public class fxh
{
        public  static void main (String args[])
        {
                for (int i=1;i<10;i++)
                {
                        for (int j=1;j<10;j++)
                        {
                                if(j<=i)
                                {
                                        System.out.print(i+"*"+j+"="+(i*j)+"");

                                        }
                                }
                                System.out.println("");
                        }
                }
}

3 个回复

倒序浏览
写得不错,赞一个
回复 使用道具 举报
如果修改成下面这样,不是循环判断的次数都变少了么
  1. public class fxh {
  2.     public  static void main (String args[])
  3.     {
  4.             for (int i=1;i<10;i++)
  5.             {
  6.                     for (int j=1;j<=i;j++)
  7.                     {
  8.                             System.out.print(j+"*"+i+"="+(i*j)+" ");
  9.        
  10.                     }
  11.                     System.out.println("");
  12.            }
  13.     }

  14. }
复制代码
回复 使用道具 举报
package Day1;

public class demo1 {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                System.out.println("你好");
//                int a=3;
//                int b;
       
//                int b=8;
//                int sum;
//                int test;
//                sum=a+b;
//                System.out.println("sum="+sum);
//                test='a'+'b';         //用阿斯科马弄
//                System.out.println(test);
                int n=9;
                for(int i=0;i<n;i++)
                {
                        for(int j=0;j<i+1;j++)
                        {
                                System.out.print((j+1)+"*"+(i+1)+"="+((j+1)*(i+1))+"\t");
                        }
                        System.out.println();
                }

        }

}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马