0

not equal to, if(j!=3,4,5)

public class Program { public static void main(String[] args) { double S=0; double n=4; double j=1; do{ if(j!=3,4,5) S=S+ Math.pow(1/(2*j+3),j/3.0); j++; System.out.println("S="+S + "j="+j); } while(j<=n+2); } }

27th Mar 2020, 3:53 PM
Angel Halili
Angel Halili - avatar
10 ответов
+ 2
Angel Halili public class Program { public static void main(String[] args) { double S=0, j=1; int n=4; do{ if(j==1 || j==2) S=S+ Math.pow(1/(2*j+3),j/3.0); j++; System.out.println("S="+S + "j="+j); } while(j<=n+2); } }
27th Mar 2020, 4:25 PM
Jayakrishna 🇮🇳
0
It doesnt output anything ...
27th Mar 2020, 3:53 PM
Angel Halili
Angel Halili - avatar
0
(j! =3,4,5) here it is equal to j!=3 only.. And false (since j=1) while(j<=n+2); (1<=4) always true because j value not changing so Infinite loop.. Terminates after timeout.. Edit: Again give some description.
27th Mar 2020, 3:59 PM
Jayakrishna 🇮🇳
0
While calculating the sum , (j) shouldnt be equal to 3 4 5
27th Mar 2020, 4:03 PM
Angel Halili
Angel Halili - avatar
0
So when j=1 it goes (1/2+3)^(1/3.0), when it comes to j= 3 , 4 , 5 it shouldnt calculate
27th Mar 2020, 4:05 PM
Angel Halili
Angel Halili - avatar
0
Angel Halili public class Program { public static void main(String[] args) { double S=0; //double n=4; double j=1; int n=4; do{ if(j!=3 && j!=4 && j!=5) //Edit use && instead of || S=S+ Math.pow(1/(2*j+3),j/3.0); j++; System.out.println("S="+S + "j="+j); } while(j<=n+2); } } Edit: If there is no difference in taking int type values in place of double type values, use Integer type only..... Above for n and j, int n,j; is better than double j, n;
27th Mar 2020, 4:06 PM
Jayakrishna 🇮🇳
0
It still calculates 3 4 and 5
27th Mar 2020, 4:20 PM
Angel Halili
Angel Halili - avatar
0
Changing at int it effects the sum
27th Mar 2020, 4:20 PM
Angel Halili
Angel Halili - avatar
0
Oh. You want when j equal to 1 or 2, s should be calculated else not...? I edit it... Edit: Angel Halili use && in place of || I edit the code above also.. Check again..
27th Mar 2020, 4:23 PM
Jayakrishna 🇮🇳
0
Thank you for your time
27th Mar 2020, 4:32 PM
Angel Halili
Angel Halili - avatar