JAVA 求不定积分
要求用户给出一个2次方程或1次(例子x^2+3x+2;x+2),上限和下限,程序识别方程是否为2次方程或1次方程,给出最后答案可以用记事本的形式发我EMAILyexins...
要求用户给出一个2次方程或1次(例子x^2+3x+2;x+2),上限和下限,程序识别方程是否为2次方程或1次方程,给出最后答案可以用记事本的形式发我EMAILyexins@vip.qq.com
展开
2个回答
2013-08-24
展开全部
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.lang.*;
public class Jifeng { public Jifeng(int a,int b , int c,int l,int u){ h1 = a;
h2 = b;
h3 = c;
lower = l;
upper = u;
} public double getResult(){
double result = 0 ;
for(int i = 0; i < count ;i++){ double x = lower+(upper-lower)*i/((double)count); double fx = (h1*x*x + h2*x + h3)*(upper-lower); result+=fx/count;
}
return result;
} public static void main (String[] args) { System.out.println("please enter as this fomat: ax^2+bx+c");
int a = 0,b = 0,c = 0,l = 0,u = 0;
try{ System.out.println("please enter a");
Scanner scanner = new Scanner(System.in);
a=scanner.nextInt();
// need a for-loop to reask the value
System.out.println("please enter b");
Scanner scanner1 = new Scanner(System.in);
b=scanner1.nextInt(); System.out.println("please enter c");
Scanner scanner2 = new Scanner(System.in);
c=scanner2.nextInt();
System.out.println("please enter lower limit");
Scanner scanner3 = new Scanner(System.in);
l=scanner3.nextInt(); System.out.println("please enter upper limit");
Scanner scanner4 = new Scanner(System.in);
u=scanner4.nextInt();
}catch(Exception e) {
System.out.println("please reinput a number");
}
Jifeng temp = new Jifeng(a,b,c,l,u);
DecimalFormat df = new DecimalFormat("#.0000"); System.out.println("The area is"+df.format(temp.getResult())); } private int h1;
private int h2;
private int h3;
private int lower;
private int upper;
private static int count = 10000000;
}
import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.lang.*;
public class Jifeng { public Jifeng(int a,int b , int c,int l,int u){ h1 = a;
h2 = b;
h3 = c;
lower = l;
upper = u;
} public double getResult(){
double result = 0 ;
for(int i = 0; i < count ;i++){ double x = lower+(upper-lower)*i/((double)count); double fx = (h1*x*x + h2*x + h3)*(upper-lower); result+=fx/count;
}
return result;
} public static void main (String[] args) { System.out.println("please enter as this fomat: ax^2+bx+c");
int a = 0,b = 0,c = 0,l = 0,u = 0;
try{ System.out.println("please enter a");
Scanner scanner = new Scanner(System.in);
a=scanner.nextInt();
// need a for-loop to reask the value
System.out.println("please enter b");
Scanner scanner1 = new Scanner(System.in);
b=scanner1.nextInt(); System.out.println("please enter c");
Scanner scanner2 = new Scanner(System.in);
c=scanner2.nextInt();
System.out.println("please enter lower limit");
Scanner scanner3 = new Scanner(System.in);
l=scanner3.nextInt(); System.out.println("please enter upper limit");
Scanner scanner4 = new Scanner(System.in);
u=scanner4.nextInt();
}catch(Exception e) {
System.out.println("please reinput a number");
}
Jifeng temp = new Jifeng(a,b,c,l,u);
DecimalFormat df = new DecimalFormat("#.0000"); System.out.println("The area is"+df.format(temp.getResult())); } private int h1;
private int h2;
private int h3;
private int lower;
private int upper;
private static int count = 10000000;
}
2013-08-24
展开全部
不定积分没学过?不过用java 求方程的解我倒是可以写出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询