A guys i need to add 1/2 +3/4 and my answer should be 5/4.

I need in java language. Please help

I just need the function.

## 8 Replies - 10927 Views - Last Post: 10 October 2007 - 02:08 PM

##
**Replies To:** fractions

### #2

## Re: fractions

Posted 06 October 2007 - 11:39 AM

jack85 you should show us some effort in code so that we could help.

### #3

## Re: fractions

Posted 06 October 2007 - 11:48 AM

PennyBoki, on 6 Oct, 2007 - 11:39 AM, said:

jack85 you should show us some effort in code so that we could help.

/* * Fraction.java * * Created on October 6, 2007, 8:39 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ /** * * @author Hakob */ import java.util.*; import java.io.*; public class Fraction { public Fraction() { } public static int gcd(int num, int Num) { if (num % Num == 0) { return Num; } else { return gcd(Num, num % Num); } } public static void main(String[] args)throws IOException { int Number; InputStreamReader reader = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(reader); System.out.println("Enter your first number"); String choice = input.readLine(); int num = Integer.parseInt(choice); System.out.println(num); System.out.println("Enter your second number"); String number = input.readLine(); int Num = Integer.parseInt(number); System.out.println(Num); num = num + Num; System.out.println("Sum " +num); } }

This post has been edited by **PennyBoki**: 06 October 2007 - 02:32 PM

### #5

## Re: fractions

Posted 06 October 2007 - 12:49 PM

Programmist, on 6 Oct, 2007 - 12:18 PM, said:

Do you understand how to add fractions? If so, then just use the same procedure in your program that you would use on paper. If you don't know how to add fractions, go here.

the problem is when I am adding 1/2 +3/4 or 1.0 + 3.0 it can't read my input.

and i don't know why it can read my numbers.

### #6

## Re: fractions

Posted 06 October 2007 - 02:20 PM

jack85, on 6 Oct, 2007 - 12:49 PM, said:

Programmist, on 6 Oct, 2007 - 12:18 PM, said:

Do you understand how to add fractions? If so, then just use the same procedure in your program that you would use on paper. If you don't know how to add fractions, go here.

the problem is when I am adding 1/2 +3/4 or 1.0 + 3.0 it can't read my input.

and i don't know why it can read my numbers.

my results are one number (ex: 1) but not 1/2 or something similar.

I need that my answer be like with fraction (ex: 3/4)

please help

### #7

## Re: fractions

Posted 06 October 2007 - 07:52 PM

you need to do it like you would on paper as said earlier..... find a common denominator, calculate the new numerators then add those numerators... you have to split the fractions at the / sign. then just stick it back in after your done doing allt he steps.

### #8

## Re: fractions

Posted 10 October 2007 - 11:59 AM

sl4ck3r, on 6 Oct, 2007 - 07:52 PM, said:

you need to do it like you would on paper as said earlier..... find a common denominator, calculate the new numerators then add those numerators... you have to split the fractions at the / sign. then just stick it back in after your done doing allt he steps.

A man I am getting my answer with pointer( ex: 1.25). How can I change 1.25 in to 5/4 in java language. Can you help me with showing me a small function that I can use in my program.

Thanks

### #9

## Re: fractions

Posted 10 October 2007 - 02:08 PM

no where in there do you convert to decimal or use decimals.

Page 1 of 1