Hey in this post i am going to share with you how to Create A Program for Fraction Subtraction in Java.

Okay let me share a picture with you then it might be more clear for you what is Fraction Subtraction. This is the calculation we studied in school. Now maybe you can remember what is a Fraction Subtraction.

Example:

But in programming we need a formula to get the same result like this . The Formula is ( A*D ) – ( B*C ) then divide by (B*D). Now below you can find out a program that is doing exactly the same thing.

## A Program for Fraction Subtraction in Java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com.practicehouse; import java.util.Scanner; public class Main { public static void main(String[] args) { float a,b,c,d; Scanner sc = new Scanner(System.in); System.out.println("Enter a: "); a = sc.nextFloat(); System.out.println("Enter b: "); b = sc.nextFloat(); System.out.println("Enter c: "); c = sc.nextFloat(); System.out.println("Enter d: "); d = sc.nextFloat(); // The Formula is ( A*D ) - ( B*C ) then divide by (B*D) System.out.println("Fraction Subtraction : = " + (((a*d)-(b*c))/(b*d)) ); } } |

OUTPUT:

1 2 3 4 5 6 7 8 9 |
Enter a: 1 Enter b: 2 Enter c: 1 Enter d: 6 Fraction Subtraction : = 0.33333334 |

Thanks for reading this post. i hope it will helped you to understand what is Fraction subtraction. if you have any question or comments please comments below . Stay Tune with Practice House. We will bring a lot of practices program for you. HAPPY CODING .. HAPPY LIVING !!!

My Nickname is Alif. I love Java, Open Source and exploring to new technologies. If you like my tutorials please share your thoughts about my work.

If you want to help others by doing donation please Help Them.

You also can connect with me via social media. Thanks