public class Yihuo { public static void sun(double a[],int m,double b[],int n,double R[],int k) { int i,j; for(i=0;i<k;i++) {//初始化 R[i]=0.0; } for(i=0;i<m;i++) {//计算各项系数 for(j=0;j<n;j++) { R[i+j]+=a[i]*b[j]; } } } public static void main(String []args) { double a[]={-4.0,5.0,2.0,-1.0,3.0,2.0}; double b[]= {-3.0,-2.0,1.0,3.0}; double R[]=new double[9]; DecimalFormat df= new DecimalFormat("0.0000000E000"); sun(a,6,b,4,R,9);//调用方法 System.out.println("多项式a(x),b(x)乘积的各项系数如下:\n"); for(int i=0;i<9;i++) { System.out.print("R["+i+"]="+df.format(R[i])+"\n"); } System.out.print("\n"); } }