2013-11-10
展开全部
这个只是警告而已,一样还是可以用。
这个警告的意思是,DataInputStream类的readLine()方法已经过时,不推荐使用了。
这个警告的意思是,DataInputStream类的readLine()方法已经过时,不推荐使用了。
2013-11-10
展开全部
你安装的jdk是最新版本吧?这些只是警告而已,编译照样还是成功的,运行也不会有问题的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-10
展开全部
import java.io.*;
public class Complex {
public double real;
public double imag;
public Complex()
{
}
public Complex(double realNum,double imagNum)
{
this.real=realNum;
this.imag=imagNum;
} public String toString(Complex complex)
{
if(complex.real==0.0)
{
if(complex.imag==0.0)
{
return " 0";
}
else
{
return (complex.imag+"i");
}
}
else
{
if((complex.imag)>0.0)
{
return (complex.real+"+"+complex.imag+"i");
}
else if((complex.imag)==0.0)
{
return (" "+complex.real);
}
else
{
return (complex.real+""+complex.imag+"i");//小心会相加的用""隔开
}
}
//return (complex.real+"+"+complex.imag+"i");
}
public Complex AddComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real+x2.real;
result.imag=x1.imag+x2.imag;
return result;
}
public Complex SubComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real-x2.real;
result.imag=x1.imag-x2.imag;
return result;
}
public Complex MulComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real*x2.real-x1.imag*x2.imag;
result.imag=x1.imag*x2.real+x1.real*x2.imag;
return result;
} public Complex DivComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=(x1.real*x2.real+x1.imag*x2.imag)/(x2.real*x2.real+x2.imag*x2.imag);
result.imag=(x1.imag*x2.real-x1.real*x2.imag)/(x2.real*x2.real+x2.imag*x2.imag);
return result;
}
//测试上述运算方法
public static void main(String[] args) throws IOException
{ System.out.print(" 请输入第一个复数:a+bi(a和b均为实数)\n a = " );
BufferedReader dis1=new BufferedReader(new InputStreamReader(System.in));
double e=Double.parseDouble(dis1.readLine());
//System.out.println("Output Integer: "+e); //测试用的System.out.print(" b = " );
BufferedReader dis2=new BufferedReader(new InputStreamReader(System.in));
double f=Double.parseDouble(dis2.readLine());
//System.out.println("Output Integer: "+f); //测试用的System.out.print(" 请输入第二个复数:c+di(c和d均为实数)\n c = " );
BufferedReader dis3=new BufferedReader(new InputStreamReader(System.in));
double g=Double.parseDouble(dis3.readLine());
//System.out.println("Output Integer: "+g); //测试用的System.out.print(" d = " );
BufferedReader dis4=new BufferedReader(new InputStreamReader(System.in));
double h=Double.parseDouble(dis4.readLine());
//System.out.println("Output Integer: "+h); //测试用的 Complex x1=new Complex(e,f);
Complex x2=new Complex(g,h);
//加法测试
Complex y1=new Complex().AddComplex(x1,x2);//减法测试
Complex y2=new Complex().SubComplex(x1,x2);//乘法测试
Complex y3=new Complex().MulComplex(x1,x2); //除法测试
Complex y4=new Complex().DivComplex(x1,x2);
//此处用的输出显示格式是(a+bi)+(c+di)=.............
System.out.println("("+new Complex().toString(x1)+")"+"+"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y1));System.out.println("("+new Complex().toString(x1)+")"+"-"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y2));System.out.println("("+new Complex().toString(x1)+")"+"*"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y3));System.out.println("("+new Complex().toString(x1)+")"+"/"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y4));}}
public class Complex {
public double real;
public double imag;
public Complex()
{
}
public Complex(double realNum,double imagNum)
{
this.real=realNum;
this.imag=imagNum;
} public String toString(Complex complex)
{
if(complex.real==0.0)
{
if(complex.imag==0.0)
{
return " 0";
}
else
{
return (complex.imag+"i");
}
}
else
{
if((complex.imag)>0.0)
{
return (complex.real+"+"+complex.imag+"i");
}
else if((complex.imag)==0.0)
{
return (" "+complex.real);
}
else
{
return (complex.real+""+complex.imag+"i");//小心会相加的用""隔开
}
}
//return (complex.real+"+"+complex.imag+"i");
}
public Complex AddComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real+x2.real;
result.imag=x1.imag+x2.imag;
return result;
}
public Complex SubComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real-x2.real;
result.imag=x1.imag-x2.imag;
return result;
}
public Complex MulComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=x1.real*x2.real-x1.imag*x2.imag;
result.imag=x1.imag*x2.real+x1.real*x2.imag;
return result;
} public Complex DivComplex(Complex x1,Complex x2)
{
Complex result=new Complex();
result.real=(x1.real*x2.real+x1.imag*x2.imag)/(x2.real*x2.real+x2.imag*x2.imag);
result.imag=(x1.imag*x2.real-x1.real*x2.imag)/(x2.real*x2.real+x2.imag*x2.imag);
return result;
}
//测试上述运算方法
public static void main(String[] args) throws IOException
{ System.out.print(" 请输入第一个复数:a+bi(a和b均为实数)\n a = " );
BufferedReader dis1=new BufferedReader(new InputStreamReader(System.in));
double e=Double.parseDouble(dis1.readLine());
//System.out.println("Output Integer: "+e); //测试用的System.out.print(" b = " );
BufferedReader dis2=new BufferedReader(new InputStreamReader(System.in));
double f=Double.parseDouble(dis2.readLine());
//System.out.println("Output Integer: "+f); //测试用的System.out.print(" 请输入第二个复数:c+di(c和d均为实数)\n c = " );
BufferedReader dis3=new BufferedReader(new InputStreamReader(System.in));
double g=Double.parseDouble(dis3.readLine());
//System.out.println("Output Integer: "+g); //测试用的System.out.print(" d = " );
BufferedReader dis4=new BufferedReader(new InputStreamReader(System.in));
double h=Double.parseDouble(dis4.readLine());
//System.out.println("Output Integer: "+h); //测试用的 Complex x1=new Complex(e,f);
Complex x2=new Complex(g,h);
//加法测试
Complex y1=new Complex().AddComplex(x1,x2);//减法测试
Complex y2=new Complex().SubComplex(x1,x2);//乘法测试
Complex y3=new Complex().MulComplex(x1,x2); //除法测试
Complex y4=new Complex().DivComplex(x1,x2);
//此处用的输出显示格式是(a+bi)+(c+di)=.............
System.out.println("("+new Complex().toString(x1)+")"+"+"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y1));System.out.println("("+new Complex().toString(x1)+")"+"-"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y2));System.out.println("("+new Complex().toString(x1)+")"+"*"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y3));System.out.println("("+new Complex().toString(x1)+")"+"/"
+"("+new Complex().toString(x2)+")"+"="
+new Complex().toString(y4));}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询