C#上手练习2(FOR语句)
using System; using System.Collections.Generic; using System.Text; namespace Kingtest02 { class Fortest { static void Main(String[] args) { Fortest Fortest = new Fortest(); Fortest.Sum(); Fortest.Factorial(); } public void Sum()//计算1到10的和 { int a = 0; for (int i = 1; i < 11; i++) { if (i == 10) { Console.Write(i + "="); a = a + i; } else { Console.Write(i + "+"); a = a + i; } } Console.WriteLine(a); } public void Factorial()//99乘法口诀 { for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { Console.Write(j + "*" + i + "=" + j * i + "\t");//\t是转义字符(制表符),如果不使用转义字符\t,则结果显示比较乱 } Console.WriteLine(); } } } }