Series Program

Series Program

Please help me to write code for this series Write a Java Method to solve the following problem: a.Evaluate the result of the series: 1-2+3-4+5-6+��+n

View Answers

March 13, 2013 at 11:28 AM

hi friend,

Try the following code may this will be helpful for you

package net.roseindia;

import java.util.Scanner;

public class SumOfSeries {

    public static void sum(int n)
    {
        int total = 0;
        for(int i=1; i<=n; i++)
        {
            if(i<n)
            {
            System.out.print(i+"+");
            }           
            total = total+i;    
        }
        System.out.println(n+" = "+total);              
    }
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter the last number : ");
        int num = scan.nextInt();
        sum(num);
    }
}

March 14, 2013 at 12:37 AM

o/p is displaying 1+2+3+4+5=15

But i need o/p as 1+2-3+4-5=-1









Related Tutorials/Questions & Answers:
Series Program
Series Program  Please help me to write code for this series Write a Java Method to solve the following problem: a.Evaluate the result of the series: 1-2+3-4+5-6+ââ?¬Â¦Ã¢â?¬Â¦+n (or ââ?¬â??n depending on value of n
Series Program
Series Program  Please help me to write code for this series Write a Java Method to solve the following problem: a.Evaluate the result of the series: 1-2+3-4+5-6+â?¦â?¦+n   hi friend, Try the following code may
Advertisements
Series program in Java - Java Beginners
Series program in Java  Wap to print the series and find the sum:- 1... the start of the series * @param 'end' holds the end of the series * @param 'series' holds the series need to be printed */ StringBuffer series
program to display the first ten terms of the series
program to display the first ten terms of the series  Write a program to display the first ten terms of the following series : 1) 1,-3,5,-7,9..... 2) 3,6,12,24..... 3) 2,5,10,17....... 4) 0,1,2,3,6............ 5) 0,3,8,15
series
series  series 2-4+6-8+..............-20
series printing
series printing  Question:- write a program to print the following series:- 0,1,3,6,15,21,28
series printing
series printing  Question:- write a program to print the following series:- 0,1,3,6,15,21,28
sum of the series
sum of the series  Program to sum the series 1+1/1!+1/2!+1/3!+....n
LOOP-HOLE SERIES GENERATION
LOOP-HOLE SERIES GENERATION  QUESTION:- WRITE A PROGRAM TO GENERATE THE FOLLOWING SERIES CALLED LOOPHOLE SERIES:- 3,5,53,13,19,7,19,13,53,5,3
LOOP-HOLE SERIES GENERATION
LOOP-HOLE SERIES GENERATION  QUESTION:- WRITE A PROGRAM TO GENERATE THE FOLLOWING SERIES CALLED LOOPHOLE SERIES:- 3,5,53,13,19,7,19,13,53,5,3
SERIES PROGRAMMING
SERIES PROGRAMMING  WAP to print the followin series till n terms: S = 1-4+9-16+25.............n
ModuleNotFoundError: No module named 'series'
ModuleNotFoundError: No module named 'series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'series' How to remove the ModuleNotFoundError: No module named 'series'
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
series
series
ModuleNotFoundError: No module named 'linear_series'
ModuleNotFoundError: No module named 'linear_series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'linear_series' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'tv-series'
ModuleNotFoundError: No module named 'tv-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'tv-series' How to remove the ModuleNotFoundError: No module named 'tv
ModuleNotFoundError: No module named 'Fibonacci-Series'
ModuleNotFoundError: No module named 'Fibonacci-Series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Fibonacci-Series' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'pelican-series'
ModuleNotFoundError: No module named 'pelican-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pelican-series' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'series-renamer'
ModuleNotFoundError: No module named 'series-renamer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'series-renamer' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'shyft.time-series'
ModuleNotFoundError: No module named 'shyft.time-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'shyft.time-series' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'time-series'
ModuleNotFoundError: No module named 'time-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'time-series' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'Ella-Series'
ModuleNotFoundError: No module named 'Ella-Series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Ella-Series' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'kisters.water.time-series'
ModuleNotFoundError: No module named 'kisters.water.time-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'kisters.water.time-series' How to remove
fibonacci series
fibonacci series  Program to print the first n fibonacci numbers using function.the program must use InputStreamReader and BufferedReader.   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.io.*; import
java programming:generating series
java programming:generating series  WAP to print series: | + || + ||| + |||| + .......... n terms
Series of long Integers
Series of long Integers  write a program to print the series of long integer number? Write a program in java to find out whether the given number is prime or not   Hello Friend, 1)Fibonacci series: import java.util.
sum of fibonacci series
sum of fibonacci series  Write a Java program to print Fibonacci series upto n and find their sum also. 0+1+1+2+3+5+8+13+21ââ?¬Â¦Ã¢â?¬Â¦Ã¢â?¬Â¦Ã¢â?¬Â¦=sum   Hi, Please see the thread Fibonacci program
TIME SERIES DOUBT
TIME SERIES DOUBT  HI.................... In my project i am using the xydataset code to show the series output or graph say. In that each series has color taken by it on itself by default means first series has red then yellow
Version of com.intersult>series dependency
List of Version of com.intersult>series dependency
Time series sorce code
Time series sorce code   hi.......... I want to show the output of my project as time series. Can u give me a simple code for time series. Where i... series forecasting the future......... source code in java swings. ? plz help
Time series sorce code
Time series sorce code   hi.......... I want to show the output of my project as time series. Can u give me a simple code for time series. Where i... series forecasting the future......... source code in java swings. ? plz help
fibonacci series logics
fibonacci series logics  A form contains 20 text fields, these fields.... Now we have fibonacci series number by which we have to find that numbers inserted by the user in fibonacci series or nearby. for each text field value. and show
java programming:generating series
java programming:generating series  Write a program to generate series: 12345 1234 123 12 1 1 12 123 1234 12345 12345   Here is a code that displays the following pattern: 12345 1234 123 12 1 1 12 123 1234
ModuleNotFoundError: No module named 'Fourier-Series-calculator'
ModuleNotFoundError: No module named 'Fourier-Series-calculator'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Fourier-Series-calculator' How to remove
ModuleNotFoundError: No module named 'odoo8-addon-l10n-pe-add-series-field'
ModuleNotFoundError: No module named 'odoo8-addon-l10n-pe-add-series-field'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo8-addon-l10n-pe-add-series-field' How
ModuleNotFoundError: No module named 'pelican-series-plugin'
ModuleNotFoundError: No module named 'pelican-series-plugin'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pelican-series-plugin' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'series-tiempo-ar'
ModuleNotFoundError: No module named 'series-tiempo-ar'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'series-tiempo-ar' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'tendril-conventions-series'
ModuleNotFoundError: No module named 'tendril-conventions-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'tendril-conventions-series' How to remove
ModuleNotFoundError: No module named 'time-series-analysis'
ModuleNotFoundError: No module named 'time-series-analysis'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'time-series-analysis' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'Fourier-Series-calculator'
ModuleNotFoundError: No module named 'Fourier-Series-calculator'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Fourier-Series-calculator' How to remove
ModuleNotFoundError: No module named 'IPP-Macro-Series-Parser'
ModuleNotFoundError: No module named 'IPP-Macro-Series-Parser'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'IPP-Macro-Series-Parser' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed'
ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed' How to remove
ModuleNotFoundError: No module named 'greendeck-time-series'
ModuleNotFoundError: No module named 'greendeck-time-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'greendeck-time-series' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'python-fourier-series-calculator'
ModuleNotFoundError: No module named 'python-fourier-series-calculator'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'python-fourier-series-calculator' How to remove
ModuleNotFoundError: No module named 'time-series-gen'
ModuleNotFoundError: No module named 'time-series-gen'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'time-series-gen' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed'
ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Fourier-Series-Calculator-bugfixed' How to remove
ModuleNotFoundError: No module named 'greendeck-time-series'
ModuleNotFoundError: No module named 'greendeck-time-series'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'greendeck-time-series' How to remove the ModuleNotFoundError
HOW TO SHOW TIME SERIES
HOW TO SHOW TIME SERIES  hi................ i require a small code in java swings to display the output as time series. Can u plz help???????? Reply....... thanks in advance
printing series in java
printing series in java  1 123 12345 1234567 12345 123 1   Here is a code for the following pattern: 1 123 12345 1234567 12345 123 1 class Pattern{ public static void main(String[] args

Ads