+ 3

Is something wrong in the code? Please tell me.

https://code.sololearn.com/c4FcPEEvX871/?ref=app

2nd Apr 2022, 8:19 AM
Anushka Awasthi
Anushka Awasthi - avatar
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...
2nd Apr 2022, 8:40 AM
Jayakrishna 🇮🇳
+ 1
You haven't declared the variable 'n' obviously.
2nd Apr 2022, 8:21 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
It's a parameter
2nd Apr 2022, 8:23 AM
Anushka Awasthi
Anushka Awasthi - avatar
0
n is not initialised
2nd Apr 2022, 8:21 AM
Abhishek Tandon
Abhishek Tandon - avatar
0
I want to print ( 1 - 2 + 3 - 4 + 5 ) and the sum of series.
2nd Apr 2022, 4:18 PM
Anushka Awasthi
Anushka Awasthi - avatar