Questions is how can we use if statements in writing our own method in java?
-
like i am doing 3 caculations in my own method with if statements but i am unable to do so. This is my own method that i have written public static double calculateFine (double velocity) { if ((velocity > 20) || (velocity < 31)) { double velocity2 = velocity * 3.00; return velocity2; } else if ((velocity < 30) || (velocity <= 40)) { double velocity2 = velocity * 8.00; return velocity2; } else if (velocity > 40) { double velocity2 = velocity * 12.00; return velocity2; } }
-
Answer:
There's nothing wrong with your code, but your logic is a bit off. In the first if statement, you probably mean AND (&&) rather than OR (||). In the second you probably want to say "velocity > 30 && velocity <=40."
MM at Yahoo! Answers Visit the source
Related Q & A:
- How can I use SSL with django?Best solution by Stack Overflow
- How can I use XMP in Sharepoint metadata?Best solution by Stack Overflow
- How can I use mongo-sync?Best solution by github.com
- How can I mount a network drive in Mac OS X in Java?Best solution by Stack Overflow
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.