從鍵盤輸入一個正整數,按數字的相反順序輸出
阿新 • • 發佈:2019-02-03
using System;
using System.Collections.Generic;
using System.Text;
namespace 按數字的相反順序輸出
{
class Program
{
static void Main(string[] args)
{
string count = "";
Console.WriteLine("輸入一個正整數");
string str = Console.ReadLine();
for (int i = 0; i < str.Length; i++)
{
count = count + str[str.Length - i - 1]; //利用字串的長度-i,還要減1,因為從0開始
// Console.WriteLine(count);
//Console.WriteLine(str[str.Length-i-1]);
}
Console.WriteLine(count);
Console.ReadKey();
}
}
}