# fractions

Page 1 of 1

## 8 Replies - 10615 Views - Last Post: 10 October 2007 - 02:08 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=34768&amp;s=6f7be6aadadbf360caf455fe23ff52df&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jack85

Reputation: 0
• Posts: 34
• Joined: 28-September 07

# fractions

Posted 06 October 2007 - 11:27 AM

A guys i need to add 1/2 +3/4 and my answer should be 5/4.
I just need the function.
Is This A Good Question/Topic? 0

## Replies To: fractions

### #2 PennyBoki

• system("revolution");

Reputation: 53
• Posts: 2,335
• Joined: 11-December 06

## Re: fractions

Posted 06 October 2007 - 11:39 AM

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

### #3 jack85

Reputation: 0
• Posts: 34
• Joined: 28-September 07

## 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;
int num = Integer.parseInt(choice);
System.out.println(num);
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

### #4 Programmist

• Refactorer in Chief

Reputation: 254
• Posts: 1,841
• Joined: 02-January 06

## Re: fractions

Posted 06 October 2007 - 12:18 PM

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.

### #5 jack85

Reputation: 0
• Posts: 34
• Joined: 28-September 07

## 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 jack85

Reputation: 0
• Posts: 34
• Joined: 28-September 07

## 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)

### #7 sl4ck3r

• D.I.C Regular

Reputation: 11
• Posts: 285
• Joined: 22-September 07

## 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 jack85

Reputation: 0
• Posts: 34
• Joined: 28-September 07

## 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 sl4ck3r

• D.I.C Regular

Reputation: 11
• Posts: 285
• Joined: 22-September 07

## Re: fractions

Posted 10 October 2007 - 02:08 PM

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