String 字母字符串代码,循环
所以我需要完成这个程序,要求用户输入一个单词,然后他需要写回“加密的”,只有数字<所以a是1,b是2<例如,如果我给“bad”这个词,它应该返回为“2114”<我制作的程序似乎总是只对单词的第一个字母执行此操作<我需要帮助的问题是,为什么这个程序在第一个字母后停止循环?我到底做得对还是完全错了?String 字母字符串代码,循环,string,loops,alphabet,String,Loops,Alphabet,所以我需要完成这个程序,要求用户输入一个单词,然后他需要写回“加密的”,只有数字
任何帮助都将不胜感激
Console.Write("Please, type in a word: ");
string start = Console.ReadLine();
string alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int c = 0; c < alphabet.Length; c++)
{
int a = 0;
if (start[a] == alphabet[c])
{
Console.Write(c + 1);
a++;
continue;
}
if (start[a] != alphabet[c])
{
a++;
continue;
}
}
Console.Write(“请输入一个单词:”);
字符串start=Console.ReadLine();
字符串字母表=“abcdefghijklmnopqrstuvxyz”;
for(int c=0;c
我用嵌套循环完成了它:
Console.Write("Please, type in a word: ");
string start = Console.ReadLine();
string alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int a = 0; a < start.Length; a++)
{
for (int c = 0; c < alphabet.Length; c++)
{
if (start[a] == alphabet[c])
{
Console.Write(c + 1);
}
}
}
Console.Write(“请输入一个单词:”);
字符串start=Console.ReadLine();
字符串字母表=“abcdefghijklmnopqrstuvxyz”;
对于(int a=0;a
在比较字符串时,至少对我来说,循环两个字符串是有意义的
您的程序在第一个字母后停止,因为您在每个循环开始时都将“a”重置为0。非常感谢您抽出时间,我非常感谢。