using System ; namespace ConsoleApp1 { class Program { static void Main ( string [] args ) { //输入单个字符 string s = Console . ReadLine (); int x = Convert . ToInt32 ( s ); Console . WriteLine ( "x={0}" , x ); //输入多个数据 s
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
//输入单个字符
string s = Console.ReadLine();
int x = Convert.ToInt32(s);
Console.WriteLine("x={0}", x);
//输入多个数据
s = Console.ReadLine();
string[] s2 = s.Split(" ");
double[] a = new double[s2.Length];
double sum = 0;
for (int i = 0; i < s2.Length; i++)
{
a[i] = Convert.ToInt32(s2[i]);
sum = sum + a[i];
}
//带格式输入输出
Console.WriteLine("和是{0},平均是{1}", sum,sum/s2.Length);
}
}
}