-4

Here is the code,

         System.out.print("Enter r1: ");
         r1 =  in.next();
         System.out.print("Enter r2");
         r2 = in.next();
         System.out.println(myR.addR(r1,r2));

r1 and r2 is initialize as Rational. Here is my question, How can I change r1=in.next (which is in string form)into a rational form? Can I write r1 = in.Rational ....any tips plzzz

markspace
  • 10,621
  • 3
  • 25
  • 39
laygnas
  • 1
  • 1

1 Answers1

0

This is very easy to solve.

Instead of r1 = in.next();, use r1 = in.nextInt() or r1 = in.nextDouble(), depending on which kind of number you want.

Alex K
  • 8,269
  • 9
  • 39
  • 57