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.

and also you have to display the answer in two lines you cannot enter the next line
such as if you have two different set of values as answer you have to display them in two lines but with your program after that you are entering the third line

that a is added n times in last term of series
and n-1 times in second last term of series
and n-2 times in third last term of series
......
.....
.....
and a is added only once in each term of series.
So u can print
System.out.println(v+a); instead of adding the a in each term.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

## Java Loops II

You are viewing a single comment's thread. Return to all comments →

it's a simple ques. you just need to print the series. look at series.. scan num=a and add 2^n.b and print.. as simple.

how i can increment the number 'n' value for getting the series, i dont know how to put loop for this, can anyone plz help me

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.

class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t=in.nextInt(); int v=0; for(int i=0;i

}

//can you help me where i went wrong

class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t=in.nextInt(); for(int i=0;i

}

you can not use ^ in java (i guess in programming ) use Math.pow(arg1,arg2) check this for more detail

check my code @ https://codeshare.io/arJ93q ask me if any issue or you can inhence my code -thank you

You can use the '^' in programming. Python, Pearl, (not sure if on Ruby is possible) are some languages that support the use of '^'.

isn't ^ XOR

u cant add " a " sum it will disturb the sum just substitute and check

^ operator is not supported in java

yes, instead of this use Math.pow() operator..... Hope this is helpful!!!!

for(int i=0;i

smart and excellent

for Math.pow j has to be double, it won't work

use type cast int as pow returns double and this code won't pass all the testcases. You need to use long to pass all the testcases

fabulous

please explain the code!

and also you have to display the answer in two lines you cannot enter the next line such as if you have two different set of values as answer you have to display them in two lines but with your program after that you are entering the third line

you cant use to the power here(2^j) you have to use math.pow() function

that a is added n times in last term of series and n-1 times in second last term of series and n-2 times in third last term of series ...... ..... ..... and a is added only once in each term of series. So u can print System.out.println(v+a); instead of adding the a in each term.

println itself means a new line so make it like

System.out.println();

Everything

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

same with me

where are you working??

but it doesn't pass through all the test cases.

yes! but test cases are not satisfiying