zoukankan      html  css  js  c++  java
  • c#复习-1

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Collections;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace ConsoleApplication1
     9 {
    10     class Program
    11     {
    12         struct student               //结构体
    13         {
    14             public int xuhao;
    15             public string xuehao;       //学号
    16             public string name;      // 姓名
    17             public decimal fenshu;   //分数
    18 
    19         }
    20         static void Main(string[] args)
    21         {
    22             //添加5个学生的信息到集合中,
    23             //每个学生都有:学号,姓名,成绩,3个内容
    24             //添加完毕后将学生的分数从高到低排列并打印出来
    25 
    26             //请输入第1个学生的学号:101
    27             //请输入第1个学生的姓名:xxx
    28             //请输入第1个学生的成绩:99
    29             //------------------------(注意加个分割线)
    30             //请输入第2个学生的学号:102
    31             //请输入第2个学生的姓名:xxx
    32             //请输入第2个学生的成绩:98
    33             //....一直到第5个输入完,然后按回车
    34             //第1个学生的学号:101,姓名:xxx:成绩:99
    35             //第2个学生....
    36             //第3个..
    37             //每段都加个分割线
    38 
    39             //1、循环添加学生信息
    40             ArrayList list = new ArrayList();
    41 
    42             for (int i = 1; i < 6; i++)
    43             {
    44                 student stu = new student(); //实例化
    45 
    46                 Console.Write("请输入第" + i + "个学生的学号:");
    47                 stu.xuehao = Console.ReadLine();
    48                 Console.Write("请输入第" + i + "个学生的姓名:");
    49                 stu.name = Console.ReadLine();
    50                 Console.Write("请输入第" + i + "个学生的成绩:");
    51                 stu.fenshu = Convert.ToDecimal(Console.ReadLine());
    52                 stu.xuhao = i;
    53 
    54                 list.Add(stu);
    55                 Console.WriteLine("===============================");
    56             }
    57 
    58             Console.WriteLine("------------------------成绩排序--------------------------");
    59 
    60             //2、排序
    61 
    62             for (int i = 0; i < list.Count - 1; i++)
    63             {
    64                 for (int j = i + 1; j < list.Count; j++)
    65                 {
    66                     student stu1 = (student)list[i];
    67                     student stu2 = (student)list[j];
    68 
    69                     if (stu1.fenshu < stu2.fenshu)
    70                     {
    71                         Object ob = list[i];
    72                         list[i] = list[j];
    73                         list[j] = ob;
    74                     }
    75                 }
    76             }
    77 
    78             //3、打印
    79             foreach (object o in list)
    80             {
    81                 student ss = (student)o;
    82                 Console.WriteLine("" + ss.xuhao + "个学生的学号:" + ss.xuehao + ",姓名:" + ss.name + ",分数:" + ss.fenshu + "");
    83             }
    84 
    85 
    86 
    87 
    88             Console.ReadLine();
    89 
    90 
    91         }
    92     }
    93 }

  • 相关阅读:
    虚拟机中对centOS7.4配置静态ip
    mybatis使用中出现的错误!
    http中get和post方法区别
    java中堆和栈的区别
    struts2工作流程
    springmvc工作流程
    JDBC访问数据库流程
    并行程序设计模式-Master-Worker模式-Guarded Suspension模式-不变模式-生产者-消费者模式的理解
    Future模式个人理解
    分布式系统一致性问题和Raft一致性算法
  • 原文地址:https://www.cnblogs.com/tonyhere/p/5592201.html
Copyright © 2011-2022 走看看