id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

calculate


NOTE: This one DOES NOT COUNT towards any assignment. It is just for fun and for practice!!! Write a method that has a single integer input parameter called num. The method does the following mathematical steps to that input parameter and returns the result: First, double num. Next, add 6 to the result of the previous step. Next, double the result of the previous step. Next, subtract two from the result of the previous step. Next, divide the result of the previous step by 4. Next, add 1/2 to the result of the previous step. Finally, subtract 3 from the previous result. Return this final result. Please think about this and write the method in the most efficient way you can think of. There is a "best solution" for this particular method!


calculate(1) → 1
calculate(2) → 2
calculate(3) → 3

...Save, Compile, Run (ctrl-enter)

public int calculate(int num) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 401

Copyright Nick Parlante 2017 - privacy