Page 209 - Computer science 868 Class 12
P. 209
18 if(i%2==0)
19 {
20 s=s - (i *i);
21 }
22 else
23 {
24 s=s+(i*i);
25 }
26 }
27 System.out.println("Sum = "+s);
28 break;
29 case 2: System.out.println("Enter nth terms ");
30 n=sc.nextInt();
31 for(i=1;i<=n;i++)
32 {
33 s=s*10+1;
34 System.out.print(s+" , ");
35 }
36 break;
37 default: System.out.println("Wrong Choice");
38 }
39 }
40 }
The output of the preceding program is as follows:
1. S = 1 - 4 + 9 - 16 + ………… to n terms
2. 1, 11, 111, 1111, … n
Enter your choice
1
Enter nth terms
5
Sum = 15
207
Statements and Scope 207

