File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes round method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "round method" Watch "round method" New topic

round method

sarathy rambha

Joined: Mar 26, 2003
Posts: 2
I see compilation while compiling below program. But since round(float) returns int, I am not sure why it thinks return type is double.

float ddd = 3.5;
int j = Math.round(ddd); possible loss of precision
found : double
required: float
float ddd = 3.5;
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
The message is talking about the first line of code, not the second. "3.5" is a double, and it gets assigned to a float.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

The Math class is not part of the exam by the way. As for the error Ulf is right, its on the first line

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15033

For float literals, you need to append a letter f to the number, like this:

float ddd = 3.5f;

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: round method
It's not a secret anymore!