Search code examples
javasyntaxfractions

How do you create a fraction in java


What would the syntax be to make a fraction, for example if I wanted to make a program that takes a fraction and adds it to another fraction. I am talking about mathematical fractions btw.


Solution

  • You need to create a class that is a wrapper for fractions. For member variables you would want integers Numerator and Denominator. You would need methods for adding, subtracting, multiplying, and dividing the fractions with each other.