AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Math.Floor

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Tukewl4u
Guest





PostPosted: Sat Oct 14, 2006 7:11 am    Post subject: Math.Floor Reply with quote



Can someone direct me in the right direction on this? I just don't
understand what it's asking.
An Application of method.floor is rounding a value to the nearest integer.
The statement y = math.floor( x + 0.5 ); will round the number x to the
nearest integer and assign the result to y. Write an application that reads
double value and uses the preceding statement to round each of the numbers
to the nearest integer. For each number proceeded, display both the original
number and rounded number.
Back to top
Hal Rosser
Guest





PostPosted: Sat Oct 14, 2006 7:11 am    Post subject: Re: Math.Floor Reply with quote



"Tukewl4u" <TuKool4u (AT) hotmail (DOT) com> wrote in message
news:Gfadnf1i4cM3wa3YnZ2dnUVZ_r2dnZ2d (AT) entouch (DOT) net...
Quote:
Can someone direct me in the right direction on this? I just don't
understand what it's asking.
An Application of method.floor is rounding a value to the nearest integer.
The statement y = math.floor( x + 0.5 ); will round the number x to the
nearest integer and assign the result to y. Write an application that
reads double value and uses the preceding statement to round each of the
numbers to the nearest integer. For each number proceeded, display both
the original number and rounded number.

Math.floor(...) does not round, to nearest int - it rounds **down**
Math.Ceil(...) rounds up
Math.round(...) may be what you're looking for - it rounds to nearest int.
... for more on the Math class reference your friendly neighborhood Java API
Back to top
Andrew Thompson
Guest





PostPosted: Sat Oct 14, 2006 7:11 am    Post subject: Re: Math.Floor Reply with quote



Tukewl4u wrote:
Quote:
Can someone direct me in the right direction on this?

'1 group' would be the right direction for this question.
Please refrain from multi-posting in future.

And as an aside, I have noticed a lot* of multi-posters
sending posts to c.l.j.programmer & help as well as
it.comp.java.

Is there some Italian web page or usenet portal or 'authority'
that is suggesting that multi-posting to 3 groups is a good idea?
(I must beat them with a big stick.)

* At least three instances, in the past 2 weeks.

(Note: X-post to c.l.j.p./c.l.j.h./i.c.j., w/ f-u to c.l.j.help only)

Andrew T.
Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Sat Oct 14, 2006 2:03 pm    Post subject: Re: Math.Floor Reply with quote

"Hal Rosser" <hmrosser (AT) bellsouth (DOT) net> writes:

Quote:
Math.floor(...) does not round, to nearest int - it rounds **down**

That's true for Math.floor(x), but not Math.floor(x + 0.5) as in the
example. In fact, the Javadocs for Math.round() says the method is
equal to (long)Math.floor(a + 0.5d)
Back to top
Tukewl4u
Guest





PostPosted: Sat Oct 14, 2006 9:10 pm    Post subject: Re: Math.Floor Reply with quote

But my example says Math.floor...how can I use this statement a round?

import java.util.Scanner;

public class MaximumFinder
{
public void determineMaximum()
{
Scanner input = new Scanner( System.in );

System.out.print("Enter three values seperated by spaces: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();

double result = maximum( number1, number2, number3 );

System.out.println( "Maximum is : " + result);

}

public double maximum ( double x, double y, double z)

{
double maximumValue = Math.floor( x + 0.5);

if ( y > maximumValue )
maximumValue = y;

if ( z > maximumValue )
maximumValue = z;

return maximumValue;
}
}
"Tor Iver Wilhelmsen" <jadedgamer (AT) hotmail (DOT) com> wrote in message
news:uk633nuaw.fsf (AT) hotmail (DOT) com...
Quote:
"Hal Rosser" <hmrosser (AT) bellsouth (DOT) net> writes:

Math.floor(...) does not round, to nearest int - it rounds **down**

That's true for Math.floor(x), but not Math.floor(x + 0.5) as in the
example. In fact, the Javadocs for Math.round() says the method is
equal to (long)Math.floor(a + 0.5d)
Back to top
Hal Rosser
Guest





PostPosted: Sun Oct 15, 2006 3:54 am    Post subject: Re: Math.Floor Reply with quote

Quote:

Math.floor(...) does not round, to nearest int - it rounds **down**

That's true for Math.floor(x), but not Math.floor(x + 0.5) as in the
example. In fact, the Javadocs for Math.round() says the method is
equal to (long)Math.floor(a + 0.5d)

ooooh! - he's rounding x , not rounding (the number in parenthesis) - ok
Back to top
Jeff
Guest





PostPosted: Mon Oct 16, 2006 4:20 pm    Post subject: Re: Math.Floor Reply with quote

Tukewl4u wrote:
Quote:
But my example says Math.floor...how can I use this statement a round?

import java.util.Scanner;

public class MaximumFinder
{
public void determineMaximum()
{
Scanner input = new Scanner( System.in );

System.out.print("Enter three values seperated by spaces: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();

double result = maximum( number1, number2, number3 );

System.out.println( "Maximum is : " + result);

}

public double maximum ( double x, double y, double z)

{
double maximumValue = Math.floor( x + 0.5);

if ( y > maximumValue )
maximumValue = y;

if ( z > maximumValue )
maximumValue = z;

return maximumValue;
}
}
"Tor Iver Wilhelmsen" <jadedgamer (AT) hotmail (DOT) com> wrote in message
news:uk633nuaw.fsf (AT) hotmail (DOT) com...
"Hal Rosser" <hmrosser (AT) bellsouth (DOT) net> writes:

Math.floor(...) does not round, to nearest int - it rounds **down**

That's true for Math.floor(x), but not Math.floor(x + 0.5) as in the
example. In fact, the Javadocs for Math.round() says the method is
equal to (long)Math.floor(a + 0.5d)


Concept - the floor function will take the integer part of the number.
So, for example, Math.floor(3.6) is 3. To use floor for rounding, you
add 0.5. So, Math.floor(3.6+.5) = 4, while Math.floor(3.1+0.5) = 3.

The only error I see in your code is that you are rounding just the x
value. Unless I misread the assignment, just assign maximumvalue the
value of x, and before you set your return value do the rounding.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.