Welcome to Dream.In.Code
Become a Java Expert!

Join 149,594 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,858 people online right now. Registration is fast and FREE... Join Now!




fractions

 
Reply to this topicStart new topic

fractions, fractions in java

jack85
6 Oct, 2007 - 10:27 AM
Post #1

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 34


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Fractions
6 Oct, 2007 - 10:39 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
jack85 you should show us some effort in code so that we could help.
User is offlineProfile CardPM
+Quote Post

jack85
RE: Fractions
6 Oct, 2007 - 10:48 AM
Post #3

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 34


My Contributions
QUOTE(PennyBoki @ 6 Oct, 2007 - 11:39 AM) *

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

CODE



/*
* 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: 6 Oct, 2007 - 01:32 PM
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Fractions
6 Oct, 2007 - 11:18 AM
Post #4

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

jack85
RE: Fractions
6 Oct, 2007 - 11:49 AM
Post #5

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 34


My Contributions
QUOTE(Programmist @ 6 Oct, 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.



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.
User is offlineProfile CardPM
+Quote Post

jack85
RE: Fractions
6 Oct, 2007 - 01:20 PM
Post #6

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 34


My Contributions
QUOTE(jack85 @ 6 Oct, 2007 - 12:49 PM) *

QUOTE(Programmist @ 6 Oct, 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.



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
User is offlineProfile CardPM
+Quote Post

sl4ck3r
RE: Fractions
6 Oct, 2007 - 06:52 PM
Post #7

D.I.C Head
Group Icon

Joined: 22 Sep, 2007
Posts: 119


Dream Kudos: 25
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

jack85
RE: Fractions
10 Oct, 2007 - 10:59 AM
Post #8

New D.I.C Head
*

Joined: 28 Sep, 2007
Posts: 34


My Contributions
QUOTE(sl4ck3r @ 6 Oct, 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.




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
User is offlineProfile CardPM
+Quote Post

sl4ck3r
RE: Fractions
10 Oct, 2007 - 01:08 PM
Post #9

D.I.C Head
Group Icon

Joined: 22 Sep, 2007
Posts: 119


Dream Kudos: 25
My Contributions
no where in there do you convert to decimal or use decimals.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:19PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month