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();
}
}
}
C#第三次试验
最新推荐文章于 2024-06-21 17:15:27 发布