刚学C#
现在边学边看书,顺便做做习题
现在遇到个问题
请各位大大帮帮忙下面是代码
using System;
class X
{
public int a,b;
}
class Dx

{   

public static void aaa()
{
X x=new X();
    Console.WriteLine("first number:");
x.a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("second number:");
x.b=Convert.ToInt32(Console.ReadLine());
}
public static void Main(String[] args)
{
X x=new X();
Console.WriteLine("please into two numbers:");
aaa();
while(x.a>10&&x.b>10||x.a<=10&&x.b<=10)
{
        Console.WriteLine("The numbers are mistake!\n" +
                  "please into again");
aaa();
}
Console.WriteLine("true");
}
}输出结果有点问题
不管我输出怎么样的2个数,都是循环,不能跳出循环
而我想法是当其中1个数大于10时,为跳出循环,请大家帮帮忙
习题说一定要用布尔逻辑比较

解决方案 »

  1.   

    你有2个
    X x=new X();
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    2个X x=new X();可以运行啊
    一个就不行了啊.....
      

  3.   

    还不明白吗aaa中的x和Main的x是2个对象你分别加一句看看
    Console.WriteLine("a={0},b={1}", x.a, x.b);
      

  4.   

    while((x.a>10&&x.b>10)||(x.a<=10&&x.b<=10))
      

  5.   

    while(x.a>10&&x.b>10||x.a<=10&&x.b<=10)
    这个时候你的x.a和x.b都是0

    你可以自己单步调试看看啊
    就是因为你有2个
    X x=new X();它们不是一回事啊
      

  6.   


        class Program
        {        class X
            {
                public int a, b;
            }
            class Dx
            {
                
                public static void aaa(out int  a,out int   b)
                {
                    //X x = new X();
                    Console.WriteLine("first number:");
                    a = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("second number:");
                    b = Convert.ToInt32(Console.ReadLine());
                }
                public static void Main(String[] args)
                {
                  X x = new X();
                    Console.WriteLine("please into two numbers:");
                    aaa(out x.a ,out x.b );
                    while (x.a > 10 || x.b > 10  )
                    {
                        Console.WriteLine("The numbers are mistake!\n" +
                                  "please into again");
                        aaa(out x.a ,out x.b);
                    }
                    Console.WriteLine("true");
                }
            }
        }
    这样就OK咯!
      

  7.   

    aaa()出什么好象和上面没有什么关系,加参树把如aaa(int a,int b),这样.
      

  8.   

    我觉得 do while  不错
      

  9.   

    rebinglunlun:"我觉得 do while  不错"你的建议我试了下
    没有 while 好
    因为do while 要至少一次循环
    所以当第一次输的数是正确的话,程序也还是要执行一次循环:)