要求能实现对分数进行加、减、乘和除法运算。
程序代码:
import java.util.*; class Rational{ double x,y; Rational(double x,double y){ this.x=x; this.y=y; } double computerArea(){ return (x/y); } } public class Ex4_4{ public static void main(String args[]){ double area1=0,area2=0; Rational num1,num2; num1=new Rational(); num2=new Rational(); Scanner reader=new Scanner(System.in); System.out.println("输入分子:"); double num1.x=reader.nextDouble(); double num2.x=reader.nextDouble(); System.out.println("输入分母:"); double num1.y=reader.nextDouble(); double num2.y=reader.nextDouble(); area1=(); area2=(); System.out.println("分数的加法运算:area1+area2="+(area1+area2)); System.out.println("分数的减法运算:area1-area2="+(area1-area2)); System.out.println("分数的乘法运算:area1*area2="+(area1*area2)); System.out.println("分数的除法运算:area1/area2="+(area1/area2)); } }这个程序的:
double num1.x=reader.nextDouble();
double num2.x=reader.nextDouble();
System.out.println("输入分母:");
double num1.y=reader.nextDouble();
double num2.y=reader.nextDouble();
有错误,但是不明白愿意。希望能说一下,谢谢!