zoukankan      html  css  js  c++  java
  • 九九乘法表的四种三角形排布方式(for循环以及while循环的互换)

    #region

    //右上
      for (int i = 1; i <= 9; i++){
        for (int j = 1; j <= 9; j++){
          if (i > j){
            Console.Write(" ");
          } else{
            Console.Write("{0}*{1}={2} ", i, j, i * j);
          }
        }
          Console.Write(" ");
      }
      Console.ReadKey();
    //右下
       for (int i = 1; i <= 9; i++){
        for (int j = 1; j <= 9; j++){

          if (i < 9 + 1 - j){
            Console.Write(" ");
          }else{
            Console.Write("{0}*{1}={2} ", i, j, i * j);
          }

        }
        Console.Write(" ");
       }
        Console.ReadKey();
        Console.Write(" 上层结束 ");



    //左上
      for (int i = 1; i <= 9; i++){
        for (int j = i; j <= 9; j++)
        {
          if (i > j){
            Console.Write(" ");
          } else{
            Console.Write("{0}*{1}={2} ", i, j, i * j);
          }
        }
        Console.Write(" ");
      }
        Console.ReadKey();
        Console.Write(" ");

    //左下
      for (int i = 1; i <= 9; i++){
        for (int j = 1; j <= 9; j++){
          if (i <j){
            Console.Write(" ");
          }else{
            Console.Write("{0}*{1}={2} ", i, j, i * j);
          }  
        }
        Console.Write(" ");
      }
        Console.ReadKey();
        Console.Write(" ");
    //右上
      for (int i = 1; i <= 9; i++){
        for (int a = 1;a < i; a++){
          Console.Write(" ");
        }
      for (int j = i; j <= 9; j++) {
        Console.Write("{0}*{1}={2} ", i, j, i * j);
      }
        Console.Write(" ");
      }
      Console.ReadKey();
      Console.Write(" ");

    #endregion

    附加运行结果:

  • 相关阅读:
    JNI实例(含代码)
    sizeof()小结
    【转】C++ 关键字——friend
    curl资料小结
    【Curl (libcurl) 开发 之一】Cocos2dx之libcurl(curl_easy)的编程教程(帮助手册)!
    JSP中统一错误信息输出
    在号码池取连续号码的算法
    常用的文件操作方法
    走出基金净值的误区
    ResultSet概论
  • 原文地址:https://www.cnblogs.com/Kai-YoungMaster/p/12375174.html
Copyright © 2011-2022 走看看