控制台应用

来源:互联网 发布:c语言swap是什么意思 编辑:程序博客网 时间:2024/04/29 19:22
.编写一个控制台应用。输入一组整数,输出所有的奇数。

  提示:使用字符串的Split函数

using System;using System.Collections.Generic;using System.Collections;using System.Linq;using System.Text;namespace test{    class Program    {        static void Main(string[] args)        {            string str = "";            Console.WriteLine("请输入一组数字,数字与数字之间用空格隔开");            str=Console.ReadLine();            //char[] strS = str.ToCharArray();            string[] strS = str.Split(' ');            Console.WriteLine("奇数有:");            for (int i = 0; i < str.Length; i++)            {                if(Convert.ToInt32(strS[i])%2!=0)                    Console.Write("{0}  ",strS[i]);                            }                      Console.ReadKey();        }    }}


0 0
原创粉丝点击