C#第三次试验

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
[实验目的]
1.进一步掌握类和对象的使用。
2.掌握字段、属性、方法(参数、重载、重写与覆盖)、继承和多态的使用。
3.掌握C#常用的基础类和集合的使用。
[实验内容]

1.编写一个控制台应用。输入一组整数,输出所有的奇数。

2.输入一个由若干字符组成的字符串,输出其中的大写字母、小写字母、数字和其他字符的个数。

3.输入学号和姓名,对不存在的学号加到hashtable类的实例中,对存在学号给出提示。结束输入后,输出学号为奇数的所有学生。

4.设计一个程序,输入10个数存入数组中,然后实现冒泡排序

 */
namespace ConsoleApplication1
{
    class number
    {
        //public int num;
        public int[] num_array = new int[100];
        public int[] odd_number = new int[100];
        public int[] even_number = new int[100];
        int odd_len;
        int even_len;
        int num_len;
        public number(string[] input)
        {
            int j = 0, k = 0;
            num_len = input.Length;
            for (int i = 0; i < input.Length; i++)
            {
                num_array[i] = int.Parse(input[i]);
                if (num_array[i] % 2 == 0)
                {
                    even_number[j++] = num_array[i];
                }
                else
                {
                    odd_number[k++] = num_array[i];
                }
            }
            even_len = j;
            odd_len = k;
        }
        public void echo_num()
        {
            for (int i = 0; i < num_len; i++)
            {
                Console.WriteLine(num_array[i]);
            }
        }
        public void echo_odd()
        {
            for (int i = 0; i < odd_len; i++)
            {
                Console.WriteLine(odd_number[i]);
            }
        }
        public void echo_even()
        {
            for (int i = 0; i < even_len; i++)
            {
                Console.WriteLine(even_number[i]);
            }
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            String str;
            str = Console.ReadLine();
            string[] num = str.Split(new char[] { ' ' });
            number number = new number(num);

            number.echo_even();
            number.echo_num();
            number.echo_odd();
            Console.ReadLine();
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值