求 java高手, 老师布置的 题目
老师布置的java题目,谁能帮帮忙,还是英文的,就是编写一个小应用程序解方程,然后要用几种固定的方法,求高手有高分...
老师布置的java题目, 谁能帮帮忙, 还是英文的, 就是编写一个 小应用程序 解方程, 然后 要用几种固定的方法 ,求高手 有 高分
展开
3个回答
展开全部
LZ其实应该自己试着做一下,我这里写了完整的解答,还有结果,自己看吧!
1. ===========================TestEx1_2.java:===========================
import java.util.*;
public class TestEx1_2 {
public static void main(String[] args) {
// read in from keyboard
Scanner s = new Scanner(System.in);
System.out.print("Please enter a: ");
double a = s.nextDouble();
System.out.print("Please enter b: ");
double b = s.nextDouble();
System.out.print("Please enter c: ");
double c = s.nextDouble();
System.out.print("Please enter d: ");
double d = s.nextDouble();
System.out.print("Please enter e: ");
double e = s.nextDouble();
System.out.print("Please enter f: ");
double f = s.nextDouble();
// calculate using Ex1_2
Ex1_2 ex = new Ex1_2(a,b,c,d,e,f);
if (ex.isConsistent())
System.out.println("The result x = "+ex.getX()+", and y = "+ex.getY());
else
System.out.println("The answer is not consistent, the denominator is zero!");
}
}
2. ===========================Ex1_2.java:===========================
public class Ex1_2 {
private double a,b,c,d,e,f;
private double x,y;
public Ex1_2(double a1,double b1,double c1,double d1,double e1,double f1) {
a = a1;
b = b1;
c = c1;
d = d1;
e = e1;
f = f1;
}
public double getX()
{
x = (c*e-b*f) / (a*e-b*d);
return x;
}
public double getY ()
{
y = (a*f-c*d) / (a*e-b*d);
return y;
}
public boolean isConsistent()
{
double denominator = (a*e-b*d);
if (denominator==0)
return false; // wrong
else
return true;
}
}
3. ===========================Sample output:===========================
Please enter a: 2.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 2.3
Please enter e: 5.0
Please enter f: 3.56
The result x = 1.459259259259259, and y = 0.040740740740740855
Please enter a: 4.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 4.0
Please enter e: 2.0
Please enter f: 6.0
The answer is not consistent, the denominator is zero!
1. ===========================TestEx1_2.java:===========================
import java.util.*;
public class TestEx1_2 {
public static void main(String[] args) {
// read in from keyboard
Scanner s = new Scanner(System.in);
System.out.print("Please enter a: ");
double a = s.nextDouble();
System.out.print("Please enter b: ");
double b = s.nextDouble();
System.out.print("Please enter c: ");
double c = s.nextDouble();
System.out.print("Please enter d: ");
double d = s.nextDouble();
System.out.print("Please enter e: ");
double e = s.nextDouble();
System.out.print("Please enter f: ");
double f = s.nextDouble();
// calculate using Ex1_2
Ex1_2 ex = new Ex1_2(a,b,c,d,e,f);
if (ex.isConsistent())
System.out.println("The result x = "+ex.getX()+", and y = "+ex.getY());
else
System.out.println("The answer is not consistent, the denominator is zero!");
}
}
2. ===========================Ex1_2.java:===========================
public class Ex1_2 {
private double a,b,c,d,e,f;
private double x,y;
public Ex1_2(double a1,double b1,double c1,double d1,double e1,double f1) {
a = a1;
b = b1;
c = c1;
d = d1;
e = e1;
f = f1;
}
public double getX()
{
x = (c*e-b*f) / (a*e-b*d);
return x;
}
public double getY ()
{
y = (a*f-c*d) / (a*e-b*d);
return y;
}
public boolean isConsistent()
{
double denominator = (a*e-b*d);
if (denominator==0)
return false; // wrong
else
return true;
}
}
3. ===========================Sample output:===========================
Please enter a: 2.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 2.3
Please enter e: 5.0
Please enter f: 3.56
The result x = 1.459259259259259, and y = 0.040740740740740855
Please enter a: 4.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 4.0
Please enter e: 2.0
Please enter f: 6.0
The answer is not consistent, the denominator is zero!
追问
哥们你有空给我讲解讲解吗?
追答
我上面已经写得挺清楚的,第一个就是叫用户打入数据a,b,c,d,e,f ,然后使用Ex1_2的方法。Ex1_2(a,b,c,d,e,f)是constructor,getX(), getY(), isConsistent()是需要的计算方法,下面3就是结果,还有不懂吗? 你也可以自己看看书。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询