Re: [問題] 九九乘法表
        其實你就觀察他由上到下,由左到右的順序應該很快就知道怎麼寫了。比較麻煩
的是要對齊。
        static void Main(string[] args)
        {
            Console.Write(" ");
            for (int m_idx = 1; m_idx <= 9; m_idx++)
                Console.Write("  " + m_idx);
            Console.WriteLine();
            for (int m_idx = 1; m_idx <= 9; m_idx++)
            {
                Console.Write(m_idx);
                for (int m_idx_y = 1; m_idx_y <= 9; m_idx_y++)
                {
                    String m_output =  (m_idx * m_idx_y).ToString();
                    if (m_output.Length == 1)
                        m_output = "  " + m_output;
                    else
                        m_output = " " + m_output;
                    Console.Write(m_output);
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
        PS:跟數字有關的迴圈還是用for比較好,看起來比較簡潔。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.167.159
※ 編輯: optimist9266    來自: 118.168.167.159      (05/04 20:06)
推
05/04 20:08, , 1F
05/04 20:08, 1F
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章