zoukankan      html  css  js  c++  java
  • 问题 F: 猜数(C#)

    题目描述

    编写一个控制台程序。以控制台方式输入整数,且调用Class1类CompareNum方法判断是否猜中,给出大了、小了、猜中三种提示。输入exit表示输入结束。

    输入

    输出

    太小了
    太大了
    猜中了

    提示

    若输入的既不是数字,又不是exit,应给出合理提示。如请输入数字!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace 猜数
    {
        class Program
        {
            static void Main(string[] args)
            {
                int m = Convert.ToInt32(Console.ReadLine());
                while (true)
                {
                    string s = Console.ReadLine();
                    if (s == "exit") break;
                    int n = Convert.ToInt32(s);
                    switch(n.CompareTo(m))
                    {
                        case -1: Console.WriteLine("太小了");
                            break;
                        case 0: Console.WriteLine("猜中了");
                            break;
                        case 1: Console.WriteLine("太大了");
                            break;
                    }
                }
     
                Console.ReadKey();
            }
        }
    }
    

      

  • 相关阅读:
    从DataGridViewer导出Excel
    C#获取特定进程CPU和内存使用率
    51 nod 1265 四点共面
    51nod 1384 全排列
    51nod 2006 飞行员配对
    codeforces 839A
    codeforce 837C
    codeforces 837B
    codoforces 837A
    GIT
  • 原文地址:https://www.cnblogs.com/mjn1/p/12523938.html
Copyright © 2011-2022 走看看