using System; 
class Test 

  public static void Main() 
  { 
      int y=0; 
      int x=Convert.ToInt32(Console.ReadLine()); 
      if(x>0) 
      { 
      y=1; 
      } 
      else 
      ( 
        if(x==0)      
    { 
    y=0; 
    } 
    else 
  { 
    y=-1; 
  } 
    ) 
    Console.WriteLine(y); 
  } 
}
你确信这种地方用小括号可以?

解决方案 »

  1.   

     else 
          ( ==>{
            if(x==0)      
        { 
        y=0; 
        } 
        else 
      { 
        y=-1; 
      } 
        ) ==> }
      

  2.   


    using System;
    class Test
    {
        public static void Main() 
      { 
          int y=0; 
          int x=Convert.ToInt32(Console.ReadLine()); 
          if(x>0) 
          { 
          y=1; 
          } 
          else if(x==0)
          { 
               y=0;    
          
        } 
        else 
      { 
        y=-1; 
      } 
        Console.WriteLine(y); 
      }
    }
      

  3.   

          int y=0; 
          int x=Convert.ToInt32(Console.ReadLine()); 
          if(x>0) 
          { 
          y=1; 
          } 
          else 
                  if(x==0)      
        { 
        y=0; 
        } 
        else 
      { 
        y=-1; 
      } 
        )     Console.WriteLine(y); 是{} 不是()
      

  4.   

    if(表达式)
    {
    //doing……
    }
    else
    {
    //doing  
    }if(表达式)
    {
    //doing……
    }
    else if(表达式)
    {
    //doing  
    }
      

  5.   

    同意楼上两位的说法,
    不过使用 Convert.ToInt32()
    确保括号内的是数字而不是字符
      

  6.   

    using System;class Test
    {
        public static void Main()
        {
            int iX = 0;
            int iY = 0;
            bool bInt = false;        while (!bInt)
            {
                bInt = int.TryParse(Console.ReadLine(), out iX);
            }        if (iX > 0)//流程分支把最可能出现的情况写在最前面
            {
                iY = 1;
            }
            else if (iX < 0)
            {
                iY = -1;
            }
            else
            {
                iY = 0;
            }        Console.WriteLine(iY);
            Console.Read();
        }
    }
      

  7.   

    using System; 
                class Test 
                { 
                  public static void Main() 
                  { 
                      int y=0; 
                      int x=Convert.ToInt32(Console.ReadLine());                   if(x>0) 
                      { 
                          y=1; 
                      } 
                      else 
                      { 
                          if(x==0)      
                          { 
                              y=0; 
                          } 
                          else 
                          { 
                              y=-1; 
                          } 
                      } 
                      Console.WriteLine(y); 
                  } 
                }