# Java Help

 Zodiac delby · November 2, 2014 Please can any one help on below : 1.      Write a program that reads from the user four integers representing the numerators and denominators of two fractions, calculates the results of the two fractions and displays the values of the fractions sum, subtraction, multiplication and division. Sample run:Enter the numerator and denominator of the first fraction: 6 4Enter the numerator and denominator of the second fraction: 8 5The sum is: 3.1The subtraction is: -0.1The multiplication is: 2.4The division is: 0.9375Answer :

## Replies

 Yasser Taha · November 3, 2014 ``import java.util.Scanner;public class JavaApplication {     public static void main(String[] args) {    System.out.println("Enter the numerator and denominator of the first fraction respectively:");    Scanner input = new Scanner(System.in);    double n1 = input.nextDouble(); //defining 1st num    double d1 = input.nextDouble(); //definding 1st denominator    System.out.println("Enter the numerator and denominator of the second fraction respectively:");    double n2 = input.nextDouble(); // 2nd num    double d2 = input.nextDouble(); // 2nd denominator    double s = n1/d1 + n2/d2; //sum    double sub = n1/d1 - n2/d2; // subtraction    double m = (n1/d1)*(n2/d2); //multiplication    double div = (n1/d1)/(n2/d2); //division    System.out.println("The sum is: " + s); //easy stuff    System.out.println("The subtraction is: " + sub);    System.out.println("The multiplication is: " + m);    System.out.println("The division is: " + div);``
• 1

## Java / Android Development

128,111 followers