File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Data Manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data Manipulation" Watch "Data Manipulation" New topic
Author

Data Manipulation

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I have written multiple IF statement in my code. Now I want to write a function which will do the same job as the IF statement is doing and I wanted to clean that big IF statement with this function call. I am new in Java and I am wondering if someone can give me a sample function which I can refer to implement this. I would really appreciate your help.

The IF statement is as below:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

Was that supposed to be the answer to the homework question in your previous post, where you had to round a value to the nearest integer ending in 5?

Then yes, that's the hard way to do it. It is possible to do that in one line of code rather than a big if-statement. (Although your code is off by 0.1 in the way it works.)

However as to whether someone can give you that line of code... no, sorry, that isn't the way we work here. But let me give you a hint: since the rounded results are 145, 155, 165, 175 and so on, they are separated by 10. So the basis of the calculation is rounding a value to the nearest 10, and then you have to modify that to get a result ending in 5.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Data Manipulation