aspose file tools*
The moose likes Beginning Java and the fly likes Which Code Are Efficient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Which Code Are Efficient" Watch "Which Code Are Efficient" New topic
Author

Which Code Are Efficient

Huzefa Zohaib
Ranch Hand

Joined: Nov 21, 2001
Posts: 40
Hello
I only want to remove the number after the given Input.
So which of the following codes are efficient and why.
-----------------------------------------------------------------
class Code{
public static void main(String[]args){
double d=20.344;
int e=(int) d;
System.out.println(e);
}
}
-----------------------------------------------------------------
class Code2{
public static void main(String[]args){
double d=20.344;
int e=(int)Math.floor(d);
System.out.println(e);
}
}
-----------------------------------------------------------------
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
I think in terms of actual execution they would both be practically equal.
Code2 does have an added overhead of having to load the Math class when you start up Code2.
[This message has been edited by Colin Kenworthy (edited November 22, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Which Code Are Efficient
 
Similar Threads
Arithmetic Exception
Confusion about wrapper classes.
var-args and overloading
valid declarations of main()
floating point division