zoukankan      html  css  js  c++  java
  • 通过一个控制台小Demo--算术题,来展示C#基本的程序结构

    /*写一个随机产生数学题,你计算出答案的程序*/
    using System;
    namespace test {
        public class test{
            /*判断是否正确*/
            public static bool fun1(int[] randoms,int readLine_info)
            {
                int right_result = randoms[0] + randoms[1];
                if (readLine_info == right_result)
                    return true;
                else
                {
                    return false;
                }
            }
            /*产生两个随机的整数*/
            public static int[] fun2() {
                int[] randoms = new int[2];
                int x, y;
                Random ran = new Random();
                x = ran.Next(1, 100);
                y = ran.Next(1, 100);
                randoms[0] = x;
                randoms[1] = y;
                Console.WriteLine(x + " + " + y + " = ?");
                return randoms;
            }
            public static void Main()
            {
                bool result = false;
                while (result) {
                    int readLine_info;
                    int[] randoms = fun2();
                    Console.WriteLine("+");
                    //string转int,使用int.Parse(str),高效不抛异常
                    readLine_info = int.Parse(Console.ReadLine());
                    fun1(randoms, readLine_info);
                    if (result == true)
                        break;
                }
            }     
           }

       }

  • 相关阅读:
    10分钟搞懂树状数组
    POJ3278 爆搜,不要像我一样作死就好
    POJ3278 爆搜,不要像我一样作死就好
    UVA 12174 播放器,滑动窗口
    UVA 12174 播放器,滑动窗口
    UVA 12627 气球胀啊胀
    UVA 12627 气球胀啊胀
    UVALive 4487 异或 并查集
    UVALive 4487 异或 并查集
    paste指令的使用
  • 原文地址:https://www.cnblogs.com/Stakes-ds/p/9234883.html
Copyright © 2011-2022 走看看