如何将 ISBN 存储在数组中?
How to store ISBN in array?
我如何使用像这样的输入 ISBN 编号 01316295910 存储在数组中?让它在屏幕上打印列表:ISBN 0 1 3 1 6 2 9 5 9 10(<=X)
这是我的代码:
int[] A = new int[10];
Console.Write("input ISBN:");
for (int i = 0; i < A.Length; i++)
{
A[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ISBN",A[i]);
}
Console.ReadLine()
我会逐步建议这个,这样你就能明白逻辑
//declare the array
int[] A = new int[10];
Console.Write("input ISBN:");
//Read the isbn from the console
string input = Console.ReadLine();
//turn that into a char array
char[] characters = input .ToCharArray();
StringBuilder sb = new StringBuilder();
sb.append("ISBN: ");
//iterate
for (int i = 0; i < characters.Length; i++)
{
sb.append(characters[i]).append(" ");
}
//print it
Console.WriteLine(sb);
我如何使用像这样的输入 ISBN 编号 01316295910 存储在数组中?让它在屏幕上打印列表:ISBN 0 1 3 1 6 2 9 5 9 10(<=X)
这是我的代码:
int[] A = new int[10];
Console.Write("input ISBN:");
for (int i = 0; i < A.Length; i++)
{
A[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ISBN",A[i]);
}
Console.ReadLine()
我会逐步建议这个,这样你就能明白逻辑
//declare the array
int[] A = new int[10];
Console.Write("input ISBN:");
//Read the isbn from the console
string input = Console.ReadLine();
//turn that into a char array
char[] characters = input .ToCharArray();
StringBuilder sb = new StringBuilder();
sb.append("ISBN: ");
//iterate
for (int i = 0; i < characters.Length; i++)
{
sb.append(characters[i]).append(" ");
}
//print it
Console.WriteLine(sb);