Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which Code Are Efficient

 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic