Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

How to write min(a,b) instead of Math.min(a,b)

Thread view: 
juergen - 19 Sep 2006 12:14 GMT
I believe I had read somewhere how to do this but I cannot remember how
to do it.
I tried
import java.lang.Math;
or
import java.lang.Math.*;
but it doesn't work. Could someone help me? Thnx!
Juergen
Chris Brat - 19 Sep 2006 12:17 GMT
import static java.lang.Math.min;

> I believe I had read somewhere how to do this but I cannot remember how
> to do it.
[quoted text clipped - 4 lines]
> but it doesn't work. Could someone help me? Thnx!
> Juergen
Arne Vajhøj - 20 Sep 2006 00:11 GMT
>> I believe I had read somewhere how to do this but I cannot remember how
>> to do it.
[quoted text clipped - 3 lines]
>> import java.lang.Math.*;
>> but it doesn't work. Could someone help me? Thnx!

> import static java.lang.Math.min;

And it requires Java 1.5 or newer.

The point is the static keyword. The * works with static too.

Arne
opalpa@gmail.com opalinski from opalpaweb - 20 Sep 2006 05:20 GMT
If you want to be able to write "min(a,b)" you can make a class method
named min that invokes Math.min(a,b).   ... Works in every jdk

static private int min(int a, int b) {
 return Math.min(a,b);
}

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/

> I believe I had read somewhere how to do this but I cannot remember how
> to do it.
[quoted text clipped - 4 lines]
> but it doesn't work. Could someone help me? Thnx!
> Juergen


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.