aspose file tools
The moose likes Beginning Java and the fly likes Simple Program For Finding Largest Float Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Simple Program For Finding Largest Float" Watch "Simple Program For Finding Largest Float" New topic
Author

Simple Program For Finding Largest Float

Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
OK! So I am a beginner in a beginner class.

I just started learning primitive Data Types and Operations and I am writing a program to receive 4 float values input from a popup window (showInputDialog method). I have to find things like average, product, sum, and (here�s the biggy) largest/smallest (and display in Output = showMessageDialog method).

I can do everything except largest/smallest (I compiled and ran, and everything else works). I could use a hint on how to find the largest/smallest value (e.g. among 4 floats) by just using Primitive Data Types and Operations. I keep on remembering (from college 20 years ago) about something like if/then/else statements, but I am not there yet. So I am stuck with +, -, *, /, &&, ||, <, >, etc.

Any help is appreciated.

Mitch
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Take a look at the javadoc for Math. You should spot something useful.

Bookmark the JavaDoc. We all use it every day! http://java.sun.com/j2se/1.4.2/docs/api/

If you really want to use only primitives and operators - not the Math class - look at if and > as in:

if (a > b) do something

If you're really rusty on things like "if" you'll need a good language reference. Somebody with more brain cells than I will chime in with links to the Sun tutorial and a list of online books and such.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
look up the api docs for Math.min() and Math.max()

declare variables
float min,max;

both min and max will be your first input.

each subsequent input you recheck min and max
min = Math.min(min,newInput);
max = Math.max(max,newInput);
Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
Thank you!

Originally posted by Stan James:
Take a look at the javadoc for Math. You should spot something useful.

Bookmark the JavaDoc. We all use it every day! http://java.sun.com/j2se/1.4.2/docs/api/

If you really want to use only primitives and operators - not the Math class - look at if and > as in:

if (a > b) do something

If you're really rusty on things like "if" you'll need a good language reference. Somebody with more brain cells than I will chime in with links to the Sun tutorial and a list of online books and such.


Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Mitch!

Originally posted by Stan James:
Somebody with more brain cells than I will chime in with links to the Sun tutorial and a list of online books and such.


Until that somebody makes an appearance, I thought you mike like to have the following list of free on-line Java tutorials and books that I have found useful:
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials
  • Interactive Programming In Java by Lynn Andrea Stein
  • Bruce Eckel's Thinking In Java
  • JavaRanch's own Campfire Stories
  • Allen B. Downey's How To Think Like A Computer Scientist

  • [ September 06, 2004: Message edited by: Dirk Schreckmann ]

    [How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
    Ilja Preuss
    author
    Sheriff

    Joined: Jul 11, 2001
    Posts: 14112
    Originally posted by Dirk Schreckmann:
    Until that somebody makes an appearance, I thought you mike like to have the following list of free on-line Java tutorials and books that I have found useful:


    Dirk, perhaps you shoud put that somewhere in the FAQ?


    The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
    Dirk Schreckmann
    Sheriff

    Joined: Dec 10, 2001
    Posts: 7023
    Good idea.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Simple Program For Finding Largest Float
     
    Similar Threads
    J2ME Problem
    Reading array elements from a file.
    Using Sun's Migration Tool...
    trouble with reflection
    Problems reading from a .txt file