programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Tim Cooke
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Devaka Cooray
• Ron McLeod
• paul wheaton
Saloon Keepers:
• Tim Moores
• Piet Souris
• Tim Holloway
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Frits Walraven
• Scott Selikoff

# java.lang.Math floor() and ceil()

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
hi,
i'm new to javaRanch I have problem understanding this code, the code is as follows:
class SRC119 {
static String m1(int i) {return "I";}
static String m1(long i) {return "L";}
static String m1(float i) {return "F";}
static String m1(double i) {return "D";}
public static void main (String[] args) {
System.out.print(m1(Math.floor(1.0f)) + m1(Math.floor(1.0d)));
System.out.print(m1(Math.ceil(1.0f)) + m1(Math.ceil(1.0d)));
}}

what is exactly happening in this code, floor() method takes the double value but here the float type
value is being passed but still the answer is coming out,
can anyone explain this code to me.

thanks,

Bartender
Posts: 1051
5
• Number of slices to send:
Optional 'thank-you' note:
Easy. A copy of the float literal is given to a double. As a double can easily hold a float value, no explicit cast is necessary. As floor and ceil always return a double, the appropriate m1 method is always called.

Ranch Hand
Posts: 924
1
• Number of slices to send:
Optional 'thank-you' note:
Welcome to www.javaranch.com. we have something called "code tags" for posting code snippets which formats your code and improves readibility vastly. to use code tags , just write down your code , select it and click on Code button above. this will present your question in a nice readable form , which will help you as well as other ranchers . Regards

author
Posts: 9050
21
• Number of slices to send:
Optional 'thank-you' note:
just fyi - the Math class is no longer a topic in the exam.

 When people donâ€™t understand what you are doing they call you crazy. But this tiny ad just doesn't care: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising