Re: [問題] 九九乘法表
我照你的格式改成 for 迴圈...
string str;
Console.Write(" ");
for(int x=1;x<10;x++)
{
str = Convert.ToString(x);
Console.Write(str.PadLeft(3));
}
Console.Write("\n");
for(int y=1;y<10;y++)
{
Console.Write(y);
for(int x=1;x<10;x++)
{
str = Convert.ToString(x * y);
Console.Write(str.PadLeft(3));
}
Console.Write("\n");
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.25.181.174
推
05/04 20:08, , 1F
05/04 20:08, 1F
→
05/04 20:09, , 2F
05/04 20:09, 2F
→
05/04 20:17, , 3F
05/04 20:17, 3F
→
05/04 21:29, , 4F
05/04 21:29, 4F
ssccg大大高招 ^_^ 程式又簡化了...為什麼可以這樣用啊?
我已經安裝 VS 2010 Express 已經可以檢驗您的說法,效果是一樣的,正確無誤。XD
這樣省掉一個字串變數的宣告...真的很精簡...^_^
Console.Write(" ");
for (int x = 1; x < 10; x++)
{
Console.Write("{0,3}", x);
}
Console.WriteLine();
for (int y = 1; y < 10; y++)
{
Console.Write(y);
for (int x = 1; x < 10; x++)
{
Console.Write("{0,3}", x * y);
}
Console.WriteLine();
}
Console.ReadLine();
※ 編輯: if4 來自: 114.25.181.174 (05/05 01:52)
※ 編輯: if4 來自: 114.25.181.174 (05/05 10:53)
→
05/05 11:15, , 5F
05/05 11:15, 5F
→
05/05 11:29, , 6F
05/05 11:29, 6F
→
05/05 12:34, , 7F
05/05 12:34, 7F
→
05/05 13:45, , 8F
05/05 13:45, 8F
→
05/05 13:46, , 9F
05/05 13:46, 9F
→
05/05 13:47, , 10F
05/05 13:47, 10F
→
05/05 13:48, , 11F
05/05 13:48, 11F
→
05/05 13:54, , 12F
05/05 13:54, 12F
→
05/05 15:45, , 13F
05/05 15:45, 13F
不加參數就可以直接印出來 Console.Write("{0,3}") 如果後面要印出 x*y
就要寫兩行,當然...這不是本問題的求解...可能在別的問題上吧 XD
Console.Write("{0,3}");
Console.Write(x * y);
※ 編輯: if4 來自: 114.25.181.174 (05/05 16:04)
→
05/05 16:27, , 14F
05/05 16:27, 14F
→
05/05 16:28, , 15F
05/05 16:28, 15F
→
05/05 16:28, , 16F
05/05 16:28, 16F
→
05/05 16:31, , 17F
05/05 16:31, 17F
→
05/05 16:36, , 18F
05/05 16:36, 18F
→
05/05 17:48, , 19F
05/05 17:48, 19F
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章