+ 3
Is something wrong in the code? Please tell me.
7 Antworten
0
//main method missing, and n undeclared..
// without errors code:
class Series
{
public static void main (String a[]) //main method drclaration
{
int s = 0 ;
int sign = -1;
int n = 15; // declare and initialize this, 15 is a sample only..
for ( int i = 1; i <= n ; i++)
{
sign *= -1;
s = s + (sign * i);
}
System.out.println("S = " +s);
}
}
//what is your task? Is it correct output?.. Hope it helps...
+ 1
You haven't declared the variable 'n' obviously.
+ 1
It's a parameter
0
n is not initialised
0
I want to print ( 1 - 2 + 3 - 4 + 5 ) and the sum of series.