如何在控制台APP中输入一行输入数字? [英] how can i enter input numbers in a line in console APP?

查看:110
本文介绍了如何在控制台APP中输入一行输入数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序正在进行排序....需要输入输入10个数字...这怎么可能...非常感谢你的帮助:)

< pre lang =c#> 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;

命名空间 ConsoleApplication1
{
class 计划
{
静态 void Main( string [] args)
{
int [] a = new int [ 10 ];
int i,j,t;
Console.WriteLine( 在排序前输入10个数字=);

for (i = 0 ; i < 10 ; i ++)
a [i] = Convert.ToInt32(Console.ReadLine()); // 这里我需要帮助plz ??
for (i = 0 ; i < 10 ; i ++)
for (j = 0 ; j < 9 ; j ++)
{
if (a [j] < a [j + 1 ])
{
t = a [j];
a [j] = a [j + 1 ];
a [j + 1 ] = t;

}

}
Console.Write( 排序后=);
for (i = 0 ; i < ; 10 ; i ++)
Console.Write(a [i] + );


Console.ReadLine();
}
}
}

解决方案




你必须使用Read()而不是ReadLine()。



 for(i = 0; i< 10; i ++) 
a [i] = Convert.ToInt32(Console.Read()); //这里我需要帮助plz ??





现在,您可以在波纹管结构中输入10个数字,并在列表末尾输入Enter Key 。

1 2 3 4 5 6 7 8 9 10现在按Enter键



我希望它对你有帮助


hi , its my program which doing sort .... in need enter input 10 numbers in a line ... how is it possible ... many thanks for ur helping :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int [] a = new int [10];
            int i,j,t;
            Console.WriteLine("Enter 10 numbers Before Sort= ");

            for (i = 0; i < 10; i++)
                a[i] = Convert.ToInt32(Console.ReadLine());   //here i need help plz??
          for (i = 0; i < 10; i++)
                for (j = 0; j < 9; j++)
                {
                    if (a[j] < a[j + 1])
                    {
                        t = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = t;
                    
                    }
                        
                    }
            Console.Write("After Sort = ");
            for (i = 0; i < 10; i++)
                Console.Write(a[i] + " , " );


            Console.ReadLine();
        }
    }
}

解决方案

Hi
You must use from Read() instead of ReadLine().

for (i = 0; i < 10; i++)
     a[i] = Convert.ToInt32(Console.Read());   //here i need help plz??



Now, You can enter 10 numbers in bellow structure and enter Enter Key in end of list.
1 2 3 4 5 6 7 8 9 10 Now Press Enter

I hope It's helpful for you


这篇关于如何在控制台APP中输入一行输入数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆