永发信息网

刚才在网上看到一个Java程序,编译显示:使用或覆盖了已过时的API,如何解决?

答案:3  悬赏:30  手机版
解决时间 2021-05-02 05:41
  • 提问者网友:半生酒醒
  • 2021-05-01 10:16
本人新手,暂时等于一问3不知的!
最佳答案
  • 五星知识达人网友:逃夭
  • 2021-05-01 11:12
这个只是警告而已,一样还是可以用。
这个警告的意思是,DataInputStream类的readLine()方法已经过时,不推荐使用了。
全部回答
  • 1楼网友:琴狂剑也妄
  • 2021-05-01 12:35

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));

}

}

  • 2楼网友:西岸风
  • 2021-05-01 11:18

你安装的jdk是最新版本吧?

这些只是警告而已,编译照样还是成功的,运行也不会有问题的。

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯