We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Just keep on trying, the answer will come up, my algorithm was something like this
create a "cumulative" variable and set it equal to user input "a"
Inside the INPUT FOR Loop
1)Create a new for loop for a variable say "j", start it from 0 to n where n is the input provided by user and already written in the code.
2)compute the part of (2^j)*b and store it in a variable say "res".
3) Now simply add the equation to the cumulative variable -> cumulative=cumulative+res(refer step 2)
4) Print (cumulative+" ")
5) Close for loop
6) user proper Println syntax tomove cursor to next line.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
Hey,
Just keep on trying, the answer will come up, my algorithm was something like this create a "cumulative" variable and set it equal to user input "a" Inside the INPUT FOR Loop 1)Create a new for loop for a variable say "j", start it from 0 to n where n is the input provided by user and already written in the code. 2)compute the part of (2^j)*b and store it in a variable say "res". 3) Now simply add the equation to the cumulative variable -> cumulative=cumulative+res(refer step 2) 4) Print (cumulative+" ") 5) Close for loop 6) user proper Println syntax tomove cursor to next line.