您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 用JAVA实现复数的四则运算
  所属分类: C
  开发工具:
  文件大小: 1kb
  下载次数: 0
  上传时间: 2010-04-28
  提 供 者: computer_*********
 详细说明: import java.io.*; public class Book{ double sb; double xb; Book(double x,double y){ this.sb=x; this.xb=y; } Book(){ } public static void main(String args[]){ System.out.println("请输入数据:"); double a=0; double b=0; double c=0; double d=0; String s; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入第一个复数的实部:"); try{ s = in.readLine(); a=Double.parseDouble(s); } catch(IOException e) { System.out.println(&quo t;抛掷异常");} System.out.println("请输入第一个复述的虚部:"); try{ s = in.readLine(); b =Double.parseDouble(s); } catch(IOException e) { System.out.println("抛掷异常");} System.out.println("请输入第二个复述的实部:"); try{ s = in.readLine(); c =Double.parseDouble(s); } catch(IOException e) { System.out.println("抛掷异常");} System.out.println("请输入第二个复述的虚部:"); try{ s = in.readLine(); d =Double.parseDouble(s); } catch(IOException e) { System.out.println("抛掷异常");} Book h; h=new Book(a,b); Book j; j=new Book(c,d); System.out.println("您输入的一个数为:"); toString(h); System.out.println("您输入的二个数为:"); toString(j); Book k; k=new Book(); char z='y'; do{ System.out.println("请选择您要进行的计算:"); System.out.println("1 :进行加法运算"); System.out.println("2 :进行减法运算"); System.out.println("3 :进行修改"); System.out.println("4 :进行乘法运算"); System.out.println("5 :进行除法运算"); System.out.println("6 :查看修改结果"); int i=0; try{ i= Integer.parseInt(in.readLine()); } catch(IOException e) { System.out.println("抛掷异常");} switch(i) { case 1: k.sb=jia(h.sb,j.sb); k.xb=jia(h.xb,j.xb); System.out.println("计算结果的实部为:"+k.sb); System.out.println("计算结果的虚部为:"+k.xb); toString(k); break ; case 2: k.sb=jian(h.sb,j.sb); k.xb=jian(h.xb,j.xb); System.out.println("计算结果的实部为:"+k.sb); System.out.println("计算结果的虚部为:"+k.xb); toString(k); break ; case 3: System.out.println("请输入您要修改哪个实数:"); int l=0; try{ l= Integer.parseInt(in.readLine()); } catch(IOException e) { System.out.println("抛掷异常");} if(l==1) { h.xiugais(h); h.xiugaix(h); } else { xiugais(j); xiugaix(j); } break ; case 4: double f=0; double e=0; f=cheng(h.sb,j.sb)+cheng(h.xb,j.xb); e=cheng(h.sb,j.xb)+cheng(h.xb,j.sb); k.sb=(double)(Math.round(f*100)/100.0); k.xb=(double)(Math.round(e*100)/100.0); System.out.println("计算结果的实部为:"+k.sb); System.out.println("计算结果的虚部为:"+k.xb); toString(k); break ; case 5: double chushu=cheng(j.sb,j.sb)-cheng(j.xb,-j.xb); double beichushus=jian(cheng(h.sb,j.sb),cheng(h.xb,-j.xb)); double beichushux=jia(cheng(h.sb,-j.xb),cheng(h.xb,j.sb)); k.sb=chu(beichushus,chushu); k.xb=chu(beichushux,chushu); System.out.println("计算结果的实部为:"+k.sb); System.out.println("计算结果的虚部为:"+k.xb); toString(k); break ; case 6: System.out.println("修改后的结果为:"); System.out.println("第一个复数:"+toString(h)); System.out.println("第二个复数:"+toString(j)); break ; } System.out.println("请问您是否还要继续 y/n:"); try{ z=(char)System.in.read(); System.in.skip(2); //忽略回车换行 } catch(IOException e){} } while(z=='y'); } public static double gets(Book a){ return a.sb; } public static double getx(Book b){ return b.xb; } public static double xiugais(Book a) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入您要修改的实部:"); double m=0; try{ m= Double.parseDouble(in.readLine()); } catch(IOException e) { System.out.println("抛掷异常");} a.sb=m; System.out.println("修改成功:"); return 0; } public static double xiugaix(Book b) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入您要修改的虚部:"); double n=0; try{ n= Double.parseDouble(in.readLine()); } catch(IOException e) { System.out.println("抛掷异常");} b.xb=n; System.out.println("修改成功:"); return 0; } public static double jia(double a,double b)// { double c=0; c=a+b; System.out.println("加法成功:"); return c ; } public static double jian(double a,double b) { double c=0; c=a-b; System.out.println("减法成功:"); return c; } public static double cheng(double a,double b) { double c=0; c=a*b; System.out.println("乘法成功:"); return c; } public static double chu(double a,double b) { double d=0; double c=0; d=a/b; c=(double)(Math.round(d*100)/100.0); System.out.println("除法成功:"); return c ; } public static double toString(Book a){ System.out.println("结果为:"+a.sb+"+"+a.xb+"*i"); return 0; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: java 复数 加减乘除运算
 输入关键字,在本站1000多万海量源码库中尽情搜索: