Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Calculate sum of series 9 + 99 + 8 + 88 ... 2 + 22 + 1 + 11

0 votes
Write a program to calculate sum of series 9 + 99 + 8 + 88 + 7 +77 + 6 + 66 + 5 + 55 + 4 + 44 + 3 + 33 + 2 + 22 + 1 + 11
asked by anonymous
edited by Ranjith
do you also want to display series or only want sum

1 Answer

0 votes

public class Series1

{
    public static void main(String args[])
    {
        int sum=0;
        for(int i=9;i>=1;i--)
        {
            System.out.print(i+" + ");
            sum=sum+i;
            int a=i*11;
            if(a==11)
            {
                sum=sum+a;
                System.out.println(a);
            }
            else
            {
                sum=sum+a;
                System.out.print(a+" + ");
            }
        }
        System.out.println("Sum of Series is "+sum);
    }
}
 
 
 
OUTPUT :-      9 + 99 + 8 + 88 + 7 + 77 + 6 + 66 + 5 + 55 + 4 + 44 + 3 + 33 + 2 + 22 + 1 + 11
                        Sum of Series is 540
 
answered by dipesh (83 points)
...