Skip to content

Instantly share code, notes, and snippets.

@GriffinG1
Created September 11, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GriffinG1/578894092390c712e745852ed07cb9d8 to your computer and use it in GitHub Desktop.
Save GriffinG1/578894092390c712e745852ed07cb9d8 to your computer and use it in GitHub Desktop.
public class AddFractions extends ConsoleProgram
{
public void run()
{
int numFirst = readInt("What is the numerator of the first fraction? ");
int denFirst = readInt("What is the denominator of the first fraction? ");
int numSecond = readInt("What is the numerator of the second fraction? ");
int denSecond = readInt("What is the denominator of the second fraction? ");
int numTotal = ((numFirst * denSecond) + (denFirst * numSecond));
int denTotal = (denFirst * denSecond);
System.out.print("The sum of " + numFirst + "/" + denFirst + " + " + numSecond + "/" + denSecond + " = " + numTotal + "/" + denTotal);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment