It doesnt outpost the correct answer... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

It doesnt outpost the correct answer...

public class Program { public static void main(String[] args) { double S=0; double x=2; double n=4; for(double k=1;k<=n+1;k++){ S=S + Math.pow((x+2*k-1),(3/2)); System.out.println(S); } } }

27th Mar 2020, 2:28 PM
Angel Halili
Angel Halili - avatar
9 Answers
0
for(int k=1;k<=n+1;k++) { S=S + Math.pow((x+2*k-1),(3.0/2)); System.out.println(S) }
27th Mar 2020, 2:50 PM
Jayakrishna 🇮🇳
+ 1
3/2 results 1 always.. So need of using power function... Edit: Angel Halili I try.. If you say what you are trying... What is your expected output..?.
27th Mar 2020, 2:35 PM
Jayakrishna 🇮🇳
0
It outputs 3.0 , 8.0 etc
27th Mar 2020, 2:28 PM
Angel Halili
Angel Halili - avatar
0
Can u write it ... i dont get it
27th Mar 2020, 2:36 PM
Angel Halili
Angel Halili - avatar
0
5.1961...., 16.376.... , 34.896.... etc
27th Mar 2020, 2:40 PM
Angel Halili
Angel Halili - avatar
0
Its like (x+2*k-1)^(3/2) , x =2 so when k=1 its 3^(3/2) = 5.196... but it gives me 3.0
27th Mar 2020, 2:42 PM
Angel Halili
Angel Halili - avatar
0
Just take a double value in 3/2 means 3.0 or 2.0 In division operation, if both are integers then result is also an integer. If any one is float or double, result will be complete division and return a double value..
27th Mar 2020, 2:45 PM
Jayakrishna 🇮🇳
0
Thanks it works now
27th Mar 2020, 2:51 PM
Angel Halili
Angel Halili - avatar
0
Angel Halili you're welcome..
27th Mar 2020, 2:55 PM
Jayakrishna 🇮🇳