RSS

C#第三章练习3.9.3

2007年08月06日 | ghSky | 浏览: 868   

Programming

练习,自己研究的
希望DX多多指点!

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

namespace Chapter03Exercise393
{
    class Exercise3_9_3
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please Input:");
            String str = Console.ReadLine();
            String str2 = str;
            String[] str1 = str.Split(new char[] { '+', '-', '*', '/' });
            string temp = str1[0];
            char mark = Convert.ToChar(str[temp.Length]);
            double ans = 0;
            double num1 = Convert.ToDouble(str1[0]);
            double num2 = Convert.ToDouble(str1[1]);
            switch (mark)
            {
                case '+': ans = num1 + num2;
                    break;
                case '-': ans = num1 - num2;
                    break;
                case '*': ans = num1 * num2;
                    break;
                case '/': ans = num1 / num2;
                    break;
                default: ans = 0;
                    break;
            }
            Console.WriteLine(str2 + "=" + ans);
            Console.ReadLine();
        }
    }
}

Leave a Reply




:wink: :twisted: :surprised: :smile: :sad: :rolleyes: :redface: :razz: :question: :neutral: :mrgreen: :mad: :lol: :idea: :exclaim: :evil: :eek: :cry: :cool: :confused: :biggrin: :arrow: