zoukankan      html  css  js  c++  java
  • 在Main中定义student的结构体,进行年龄从大到小依次排序录入学生信息。(结构体的用法以及冒泡排序)

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    
    
    namespace c编程练习题
    {
       
        class Program
        {
           public  struct student               //结构体的用法。
           {
              public int code;
              public string name;
              public int old;
             }
     static void Main(string[] args)
            {
                    Console.WriteLine("请输入学生的人数");
                    int count = int.Parse(Console.ReadLine());
                    ArrayList arr=new ArrayList();
                    for (int i = 0; i < count; i++)
                    {
    
                        student s = new student();
                        Console.WriteLine("学号:");
                        s.code = int.Parse(Console.ReadLine());
                        Console.WriteLine("姓名:");
                        s.name = Console.ReadLine();
                        Console.WriteLine("年龄:");
                        s.old = int.Parse(Console.ReadLine());
                        arr.Add(s);
                    }
                    for (int i = 0; i <count; i++)
                    {
                        for (int j = i+1; j < count ; j++)
                        {
                            if (((student)arr[i]).old<((student)arr[j]).old)
                            {
                                student temp = (student)arr[i];
                               arr[i] = arr[j];
                               arr[j] = temp;
                            }
                        }
                    }
                    Console.WriteLine("学号     姓名      年龄    从大到小依次排列");
                    foreach (student s in arr)
                    {
                        Console.Write("{0}     {1}      {2}
    ",s.code,s.name,s.old);
                    }
                    Console.ReadLine();
    
            
            }
        }
    }
  • 相关阅读:
    新一轮人工智能的兴起引发的思考
    企业应用架构的发展演进
    利用poi插件,把Excel内容读入Java,把Java中的内容输出到Exce
    mysql免安装被指
    正则表达式大全
    开发数据库步骤
    JVM
    Java面试题一
    java集合总结
    JAVA WEB回顾一
  • 原文地址:https://www.cnblogs.com/kangshuai/p/4576453.html
Copyright © 2011-2022 走看看