此程序打印字符串输入的所有可能性,例如,如果输入为abc',输出应该是组合,这可以工作但是当我创建arraylist时它打印出数字而不是字符串组合,代码:
string input = Console.ReadLine();
int sl = input.Length;
ArrayList arr = new ArrayList();
for (int three = 0; three < sl; three++) {
for (int two = 0; two < sl; two++) {
for (int one = 0; one < sl; one++) {
char onef = input[one];
char twof = input[two];
char threef = input[three];
arr.Add(threef + twof + onef);
Console.Write(threef);
Console.Write(twof);
Console.WriteLine(onef);
}
}
}
Console.WriteLine("The elements of the ArrayList are:");
foreach(object obj in arr) {
Console.WriteLine(obj);
}
arraylist的输出是数字,而不是字符串字符,帮助!
答案 0 :(得分:2)
只需更改这三行
即可发件人:强>
char onef = input[one];
char twof = input[two];
char threef = input[three];
要强>
string onef = input[one].ToString();
string twof = input[two].ToString();
string threef = input[three].ToString();
答案 1 :(得分:2)
替代:改变一行:
arr.Add(string.Format("{0}{1}{2}", a, b, c));
char
不能像string
那样连接在一起。 +
以数字解释。