Computer Science, asked by Anonymous, 4 months ago

WAP to print this series in JAVA
Sum=+1+5+2+4+3+3+4+2+5+1=30

Answers

Answered by BrainlyProgrammer
2

Question:-

  • To print in JAVA the following series

Sum=+1+5+2+4+3+3+4+2+5+1=30

_______

Code:-

package Coder;

public class Series {

public static void main(String[] args) {

System.out.print("Sum=");

int c=5,d=1,s=0;

for(int i=1;i<=10;i++)

{

if (i%2==0)

{

System.out.print("+"+c);

s+=c;

c--;

}

else

{

System.out.print("+"+d);

s+=d;

d++;

}

}

System.out.print("="+s);

}

}

_______

Variable Description:-

i:-loop variable

s:- to store the sum of the numbers

d and c:- local variable

Output Attached

Attachments:
Similar questions