日期:2014-05-20  浏览次数:20653 次

很基础的问题,大家看看
已知x+y=a;x-y=b;,求X,Y。
用程序如何写啊?

------解决方案--------------------
public class Jiajianfa //已知x+y=a;x-y=b;,求X,Y
{
public static void main(String[] args)
{
int x,y;
x=0;
y=0;
for(x=1;x <1000;x++)
{
for(y=1;y <1000;y++)
{
if (x+y==8&&x-y==2)
{
System.out.println( "X和Y的值分别是: "+x+ "和 "+y);
System.out.println( "哦哦哦 ");
}
}
}
}

}

是这样的吗?
------解决方案--------------------
这题贼简单,哈哈
package test1;
public class Test13 {
public static void count(int a,int b){
float x,y;
x=(float)(a+b)/2;
y=(float)(a-b)/2;
System.out.println( "x= "+x+ "; "+ "y= "+y);
}
public static void main(String[] args) {
count(8,3);
}
}
------解决方案--------------------
代码如下
package test1;
public class Test13 {
public static void count(int a,int b){
float x,y;
x=(float)(a+b)/2;
y=(float)(a-b)/2;
System.out.println( "x= "+x+ "; "+ "y= "+y);
}
public static void main(String[] args) {
count(8,3);
}
}


------解决方案--------------------
第一步 输入x值和y值
x=a-y;

a-2y=b;

y=(a-b)/2;
print(y);
print(a-y);


ok?