C#作业处理

2019.9.8

 

作业要求:

将字符串加密,即将字符串中每个字符向后移动五个字符,并输出密文

 

解决方案:

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace AfterClassDemo
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string s = "Thursday is my lucky day!!!";
14             string s1 = null;
15             int i = 0;
16             
17             //作业:以密文形式输出字符串(向后移动五个字符)
18             for(;i < s.Length ;i++ )
19             {
20                 s1 = Convert.ToString(Convert.ToChar(Convert.ToInt32(s[i]) + 5));
21                 Console.Write(s1);
22             }
23             Console.ReadLine();
24         }
25     }
26 }

运行结果:

 

 

 

 

解题思路:

第一步:将字符串中字符转化为数字,向后移动五位

第二步:将数字转化为字符

第三步:将字符转化为字符串

posted @ 2019-09-08 10:03  二零三  阅读(187)  评论(0编辑  收藏  举报