Find floor value of a number using Math.floor

  1. /*
  2.   Find floor value of a number using Math.floor
  3.   This java example shows how to find a floor value of a number using floor method
  4.   of Java Math class. floor method returns the largest interger which is not grater
  5.   than the value.
  6. */
  7.  
  8. public class FindFloorValueExample {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. /*
  13.   * To find a floor value, use
  14.   * static double floor(double d) method of Math class.
  15.   *
  16.   * It returns a largest integer which is not grater than the argument value.
  17.   */
  18.  
  19. //Returns the same value
  20. System.out.println(Math.floor(70));
  21.  
  22. //returns largest integer which is not less than 30.1, i.e. 30
  23. System.out.println(Math.floor(30.1));
  24.  
  25. //returns largest integer which is not less than 15.5, i.e. 15
  26. System.out.println(Math.floor(15.5));
  27.  
  28. //in this case it would be -40
  29. System.out.println(Math.floor(-40));
  30.  
  31. //it returns -43.
  32. System.out.println(Math.floor(-42.4));
  33.  
  34. //returns 0
  35. System.out.println(Math.floor(0));
  36.  
  37. }
  38. }
  39.  
  40. /*
  41. Output would be
  42. 70.0
  43. 30.0
  44. 15.0
  45. -40.0
  46. -43.0
  47. 0.0
  48. */

Post new comment

To combat spam, please enter the code in the image.


Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!