static void Main(string[] args)
        {
            char c;
            int l = 0, d = 0, o = 0;
            Console.WriteLine("请输入字符:");
            c = (char)Console.Read();
            while (c!= '\n')
            {
                if (c>= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
                    l++;
                else if (c >= '0' && c <= '9')
                    d++;
                else
                    o++;
                c = (char)Console.Read();            }
                        Console.WriteLine("{0},{1},{2}",l,d,o);
            Console.ReadLine();
        } 问题:
     每次输入非数字或非字母的个数总是多一个? 这是为什么?用C语言写之后就没有这种情况 。。

解决方案 »

  1.   

    啥东西是非数字非字母?!@#%%…………&%&%输入的是这种东西??
      

  2.   


                int l = 0, d = 0, o = 0;
                Console.WriteLine("请输入字符:");
                string str = Console.ReadLine();
                foreach (char c in str)
                {
                    if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
                        l++;
                    else if (c >= '0' && c <= '9')
                        d++;
                    else
                        o++;
                }
                Console.WriteLine("{0},{1},{2}", l.ToString(), d.ToString(), o.ToString());             Console.ReadKey();
      

  3.   

    嘿嘿 。 其实这个好解决。 ..
    取巧就可以.
     Console.WriteLine("{0},{1},{2}",l,d,o);
    改:
     Console.WriteLine("{0},{1},{2}",l,d,o-1);吼吼~
      

  4.   

    两种语言的编译器本来就不一样,C# i++和++i的扩展用法和C语言也许就不一样
    比如说这个
     void main(){
      int i=5,j=5,p,q;
      p=(i++)+(i++)+(i++);
      q=(++j)+(++j)+(++j);
      printf("%d,%d,%d,%d",p,q,i,j);
    }
    你可以用C# 和C格式一下,看结果是不是一样,好像我记得Java里就不一样
      

  5.   

    因为回车符是'\r\n'吗,而循环没判断'\r'。看第5行。
            static void Main(string[] args)
            {
                char c;
                int l = 0, d = 0, o = 0;
                Console.WriteLine("请输入字符:");
                c = (char)Console.Read();
                while (c != '\n' && c != '\r')
                {
                    if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
                        l++;
                    else if (c >= '0' && c <= '9')
                        d++;
                    else
                        o++;
                    c = (char)Console.Read();            }
                Console.WriteLine("{0},{1},{2}", l, d, o);
                Console.ReadLine();
            }
      

  6.   

    太谢谢你们了。。 我知道了C和C#的换行的区别的,,这就是C语言的严谨啊。。好好学习。。朋友 们