Question: Hey I wrote this code but still I am getting error. import java.math. * ; import java.util.Scanner; public class Exercise 1 3 _ 1 5

Hey I wrote this code but still I am getting error.
import java.math.*;
import java.util.Scanner;
public class Exercise13_15{
public static void main(String[] args){
// Prompt the user to enter two Rational numbers
Scanner input = new Scanner(System.in);
System.out.print("Enter rational number1 with numerator and denominator seperated by a space: ");
String n1= input.next();
String d1= input.next();
System.out.print("Enter rational number2 with numerator and denominator seperated by a space: ");
String n2= input.next();
String d2= input.next();
RationalUsingBigInteger r1= new RationalUsingBigInteger(new BigInteger(n1), new BigInteger(d1));
RationalUsingBigInteger r2= new RationalUsingBigInteger(new BigInteger(n2), new BigInteger(d2));
// Display results
System.out.println(r1+"+"+ r2+"="+ r1.add(r2));
System.out.println(r1+"-"+ r2+"="+ r1.subtract(r2));
System.out.println(r1+"*"+ r2+"="+ r1.multiply(r2));
System.out.println(r1+"/"+ r2+"="+ r1.divide(r2));
System.out.println(r2+" is "+ r2.doubleValue());
}
}
class RationalUsingBigInteger {
private BigInteger numerator;
private BigInteger denominator;
public RationalUsingBigInteger(BigInteger numerator, BigInteger denominator){
this.numerator = numerator;
this.denominator = denominator;
if (denominator.signum()==-1){
this.numerator = this.numerator.negate();
this.denominator = this.denominator.negate();
}
BigInteger gcd = this.numerator.gcd(this.denominator);
this.numerator = this.numerator.divide(gcd);
this.denominator = this.denominator.divide(gcd);
}
// Other methods go here
}
Th error is
Compiler error messages
Exercise13_15.java:28: error: class, interface, or enum expected
import java.math.*;
^
Exercise13_15.java:29: error: class, interface, or enum expected
import java.util.Scanner;
^
2 errors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!