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); } }
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);
}
}
0
It doesnt output anything ...
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.
0
While calculating the sum , (j) shouldnt be equal to 3 4 5
0
So when j=1 it goes (1/2+3)^(1/3.0), when it comes to j= 3 , 4 , 5 it shouldnt calculate
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;
0
It still calculates 3 4 and 5
0
Changing at int it effects the sum
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..
0
Thank you for your time