fractions

fractions in java

Page 1 of 1

8 Replies - 9775 Views - Last Post: 10 October 2007 - 02:08 PM Rate Topic: -----

#1 jack85  Icon User is offline

  • New D.I.C Head

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

fractions

Post icon  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 need in java language. Please help
I just need the function.
Is This A Good Question/Topic? 0
  • +

Replies To: fractions

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 jack85  Icon User is offline

  • New D.I.C Head

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

Re: fractions

Posted 06 October 2007 - 11:48 AM

View PostPennyBoki, 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

Was This Post Helpful? 0
  • +
  • -

#4 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 251
  • View blog
  • Posts: 1,833
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 jack85  Icon User is offline

  • New D.I.C Head

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

Re: fractions

Posted 06 October 2007 - 12:49 PM

View PostProgrammist, 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.
Was This Post Helpful? 0
  • +
  • -

#6 jack85  Icon User is offline

  • New D.I.C Head

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

Re: fractions

Posted 06 October 2007 - 02:20 PM

View Postjack85, on 6 Oct, 2007 - 12:49 PM, said:

View PostProgrammist, 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
Was This Post Helpful? 0
  • +
  • -

#7 sl4ck3r  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#8 jack85  Icon User is offline

  • New D.I.C Head

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

Re: fractions

Posted 10 October 2007 - 11:59 AM

View Postsl4ck3r, 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
Was This Post Helpful? 0
  • +
  • -

#9 sl4ck3r  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1