xboxscene.org forums

Author Topic: Java Math Class Question  (Read 63 times)

dman7

  • Archived User
  • Full Member
  • *
  • Posts: 194
Java Math Class Question
« on: December 14, 2005, 09:04:00 PM »

I have a couple of Java questions I was wondering if anyone could answer:

1). In this one statement, which takes the greatest common denominator and places it in the variable commom:

int common = gcd (Math.abs(numerator), denominator);

A).What is gcd? I looked it up and it's not a reserved word in the math class. In the class that this statement comes from there is no variable, object, or method named gcd. There is also no gcd variable, object, or invoked method in the client code that uses the class that this statement comes from.
 
B ). I know that abs is a method of the math class for the absolute value of a number(in this case the number inside the variable numerator.). And I know that when the abs method is invoked it sends the variable 'numerator' as the parameter for the data to take the absolute value of. What I don't understand is the syntax of this statement in regards to  how you can take the absolute value of the variable 'denominator' haveing a variable 'numerator' inclosed in the parenthesis and simpley adding a comma to include the variable 'denominator' in the argument to be sent in the invocation of the abs method. It seems like this would be the correct syntax: int common = (Math.abs(numerator))/(Math.abs(denominator));

Can anyone explain the 'int common = gcd (Math.abs(numerator), denominator);'
 statement?

Thanks,
-dman

Logged

dman7

  • Archived User
  • Full Member
  • *
  • Posts: 194
Java Math Class Question
« Reply #1 on: December 15, 2005, 12:50:00 AM »

never mind, I made a stupid mistake.
Logged

yaazz

  • Archived User
  • Hero Member
  • *
  • Posts: 1370
Java Math Class Question
« Reply #2 on: December 16, 2005, 07:45:00 AM »

gcd is a method. anythhing with brackets is a method, anything without is a variable.

But just so you know, variables should not be able to be modified outside of the class itself, so you make methods to change the variable
Logged