int n = 0; string[] words = new string[10]; int[] times = new int[10]; Console.WriteLine("请输入一个句子:"); string b = "Console.ReadLine()"; for (int i = 0; i < string.Length(b) - 2; i++) { bool isSame = false; string source =string.Substring(i, 2); int j = i + 2; while (j < string.Length(b) - 2) { string target = string.Substring(j, 2); if (source == target) { times[n]++; if (Array.IndexOf(words, target) == -1) { isSame = true; words[n] = target; } } j++; } if (isSame) n++; } String.Format("一共有{0}个重复的词汇!\n\n其中,", n); for (int i = 0; i < 10; i++) { if (!String.IsNullOrEmpty(words[i])) { } }
1 回答
已采纳
一毛钱
TA贡献156条经验 获得超57个赞
string b = "Console.ReadLine()";这块不应该带双引号
string source =string.Substring(i, 2); 这块应该是 string source =b.Substring(i, 2);
while (j < string.Length(b) - 2) 这块应该是b.Length
string target = string.Substring(j, 2);这块应该是string target = b.Substring(j, 2);
还有好多问题,建议你去看看书
- 1 回答
- 1 关注
- 2115 浏览
添加回答
举报
0/150
提交
取消