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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 许大虾 中级黑马   /  2013-5-31 01:47  /  2359 人查看  /  17 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 许大虾 于 2013-6-3 15:09 编辑
  1. for (int i = 1; i <= 9; i++)
  2. {
  3. for (int j = 1; j <= 9; j++)
  4. {
  5. Console.WriteLine("{0}X{1}={2:00}", i, j, i * j);
  6. }
  7. Console.WriteLine();

  8. }
  9. Console.ReadKey();
复制代码
运行结果:

换成矩形, 谁改下~

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

17 个回复

倒序浏览
本帖最后由 许庭洲 于 2013-5-31 07:32 编辑

class FunctionTest
{
    public static void Main(String[] args)
    {
        draw(5,8);
        printHr();

        draw(6,10);
        printHr();

        print99(6);
        printHr();

    }

    public static void draw(int row, int col)
    {
        for (int x=0; x<row; x++)
        {
            for (int y=0; y<col; y++)
            {
                Console.WriteLine("* ");
            }
            Console.WriteLine();
        }
    }

    public static void printHr()
    {
        Console.WriteLine("----------------");
    }

    public static void print99(int q)
    {
        for (int x=1; x<=q; x++)
        {
            for (int y=1; y<=x; y++)
            {
                Console.WriteLine(y+"*"+x+"="+x*y+"t");
            }
            Console.WriteLine();
        }
    }
}

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

回复 使用道具 举报
  1. /// <summary>
  2.         /// 矩形
  3.         /// </summary>
  4.         /// <param name="col">行宽</param>
  5.         public static void DrawRange(int col)
  6.         {
  7.             int i = 1;
  8.             for (int x = 1; x < 9; x++)
  9.             {
  10.                 for (int y = 1; y < 9; y++)
  11.                 {
  12.                     Console.Write(y + "*" + x + "=" + x * y + "\t");
  13.                     if (i++ >= col)
  14.                     {
  15.                         Console.WriteLine();
  16.                         i = 1;
  17.                     }
  18.                 }
  19.             }
  20.             Console.WriteLine();
  21.         }
复制代码
  1. /// <summary>
  2.         /// 三角形
  3.         /// </summary>
  4.         /// <param name="q">输出到q*q结束</param>
  5.         public static void DrawTriangle(int q)
  6.         {
  7.             for (int x = 1; x <= q; x++)
  8.             {
  9.                 for (int y = 1; y <= x; y++)
  10.                 {
  11.                     Console.Write(y + "*" + x + "=" + x * y + "\t");
  12.                 }
  13.                 Console.WriteLine();
  14.             }
  15.         }
复制代码

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

回复 使用道具 举报
  1. //外循环 i 控制行数
  2.                 for(int i=1;i<=9;i++)
  3.                 {
  4.                         //内循环 j 控制列数
  5.                         for(int j=1;j<=i;j++)
  6.                         {
  7.                                  Console.Write(j+"*"+i+"="+j*i+"\t");
  8.                         }
  9.                         //外循环一次 换行一次
  10.                          Console.WriteLine();
  11.                 }
复制代码

点评

谢谢  发表于 2013-6-3 15:20

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

回复 使用道具 举报
楼主的问题在于,Console.WriteLine();会自动换行,改用 Console.Write就行喽

点评

明白~谢谢  发表于 2013-6-3 15:07
回复 使用道具 举报
for (int i = 1; i <= j; i++)

{

for (int j = 1; j <= 9; j++)

{

Console.Write("{0}X{1}={2}", i, j, (i * j));
Console.Write(“\t”); //使每一列对齐,看起来舒服。


}

}

Console.ReadKey();
楼主的问题在于第一个Console.WriteLine()输出应该改写为Console.Write(),这样在内循环控制的输出就不会没输出一行就换行。
Console.WriteLine()与Console.Write()的主要区别就在于输出后是否换行。
如以上的分析不妥请指出,彼此相互学习,一起朝着黑马的大门一步步的迈进。谢谢

回复 使用道具 举报
非常抱歉 上面的那个发错了 请参考下面的这个 。
for (int i = 1; i <=9; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0}X{1}={2}", i, j, (i * j));
Console.Write(“\t”); //使每一列对齐,看起来舒服。
}
}
Console.ReadKey();
楼主的问题在于第一个Console.WriteLine()输出应该改写为Console.Write(),这样在内循环控制的输出就不会没输出一行就换行。
Console.WriteLine()与Console.Write()的主要区别就在于输出后是否换行。
如以上的分析不妥请指出,彼此相互学习,一起朝着黑马的大门一步步的迈进。谢谢

点评

还是不行  发表于 2013-6-3 15:05

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

回复 使用道具 举报
王盛 中级黑马 2013-5-31 16:29:02
8#
很简单啦~ 你输出的时候错误的地方是{
Console.WriteLine("{0}X{1}={2}", i, j, (i * j));  你只需改成 Write即可!!!~~~~~~~
如果想更美观一些 可以在加一句~!
Console.Write(“\t”); //   /t 转义符(对齐的意思),只是为了美观而已,可以不加/t{:soso_e100:}

点评

谢谢~  发表于 2013-6-3 15:07
回复 使用道具 举报
console.write("\t");
回复 使用道具 举报
把内循环的Console.WriteLine改成Console.Write不用换行
回复 使用道具 举报
if(i==9){
Console.Write("\n");
}
回复 使用道具 举报
把内循环中的   Console.WriteLine   换成 Console.Write 试试
回复 使用道具 举报
ljh4282158 发表于 2013-6-10 22:41
把内循环中的   Console.WriteLine   换成 Console.Write 试试

简单明了,我也想说这个确实可以。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马