• C# 简单的例子。


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;

    namespace MyLunch
    {
        /// <summary>
        /// switch的用法
        /// </summary>
        ///
        public class Number
        {
             ArrayList list = new ArrayList();
            int[] intList;
            public Number()
            {

            }
            public void Input()
            {

                Console.WriteLine("这个程序是让你输入三个数,然后再按照顺序排列出来。(按X退出)");
              
                string Input;
             
                for (; ; )
                {
                    Input = Console.ReadLine();
                    if ("X" == Input.ToUpper())
                        break;
                    else
                        list.Add(Input);


                }

            }
            public void Sort()
            {
               intList = new int[list.Count];

                Console.WriteLine(list.Count);

                //附值.

                for (int i = 0; i < list.Count; i++)
                {
                    intList[i] = int.Parse(list[i].ToString());

                }
                for (int i = 0; i < intList.Length; i++)
                {
                    for (int j = i + 1; j < intList.Length; j++)
                    {
                        int temp;
                        if (intList[i] > intList[j])
                        {
                            temp = intList[j];
                            intList[j] = intList[i];
                            intList[i] = temp;


                        }

                    }


                }
            }
            public void Display()
            {
                foreach (var item in intList)
                {
                    Console.WriteLine(item.ToString());

                }
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Number number = new Number();
                number.Input();
                number.Sort();
                number.Display();
          
              
            


            }
        }
    }

    //另外一个例子。都是蛮简单的。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("欢迎光临本商场"+"\n"+"你今天花了多少钱啊?");
                int input=int.Parse((Console.ReadLine()));

                string Display;
                if (input<5)
                {
                    Display="你可以走了!";
                   
                }
                else if(input>5&&input<20)
                {
                    Display="奖励你一杯咖啡!";
                }
                else if(input>20&&input<30)
                {
                    Display="送你五块钱";

                }
                else if(input>30&&input<50)
                {
                    Display="你是疯子哇!";

                }
                else
                {
                    Display="早点回去睡觉吧!";
                }

                Console.WriteLine(Display+"\n再见!不送。");
                    

             
            }
        }
    }

  • 相关阅读:
    HDU5779 Tower Defence
    Python练习题2.14求整数段和
    Python练习题2.13分段计算居民水费
    Python练习题2.12输出三角形面积和周长
    Python练习题2.11求平方与倒数序列的部分和
    Python练习题2.9比较大小
    Python练习题2.8转换函数使用
    Python练习题2.7产生每位数字相同的n位数
    Python练习题2.6求交错序列前N项和
    Python练习题2.5求奇数分之一序列前N项和(存在问题)
  • 原文地址:https://www.cnblogs.com/fat_li/p/1853911.html
Copyright © 2020-2023  润新知