nikhilboorla
Series Program
2 Answer(s)      3 months and 7 days ago
Posted in : Java Beginners

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 Pages:
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
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
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
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: import java.io.*; import java.util.
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
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
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. Thanks
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.
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
Java programming: generating series
Java programming: generating series  Write a program to accept a string using buffered reader and replace character sequence 'cat' with 'dog'   Here is a java code that accept the string from the user using
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
1.Computing cos(x) using the cosine series: Recall that cos(x) is given by the following series: - Java Interview Questions
1.Computing cos(x) using the cosine series: Recall that cos(x) is given by the following series:   Write a program to compute cosine of a number x using the above series. Ignore terms less than 0.00001.  Hi friend
SERIES PROGRAMMING
SERIES PROGRAMMING  WAP to print the followin series till n terms: S = 1-4+9-16+25.............n
Ordinal Numbers Series Program in Java
Ordinal Numbers Series Program in Java An ordinal number shows a relative position, e.g., 1st, 2nd, 3rd, 4th,etc. In other words, ordinal numbers series are the words representing the rank of a number with respect to some order
Fibonacci series in java
Fibonacci series in java In this section you will learn about fibonacci number... value proceeding it. Here is the code for Fibonacci program: import... and execute the program output will look like as follows: Download SourceCode
java programming:generating series
java programming:generating series  WAP to print series: | + || + ||| + |||| + .......... n terms
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
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
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
Fibonacci program
fibonacci numbers they would like the program to print. I need to use a main...(); long[] series = new long[length]; series[0] = 0; series[1] = 1... enter the first number of the Fibonacci series: "); //firstInt = first.nextInt
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
netbeans program
with books. A Graphical User Interface (GUI) is not required, i.e. your program... number of items. Your program should provide a menu of options to work... in the library 3) Lending an item 4) Returning an item 5) Exiting the program
This series of progressive examples shows a typical pattern for building simple applications with a window.
Java NotesAbout Examples This series of progressive examples shows... Window shows a main program that creates an empty window (JFrame). Example - Second Window shows a main program with a subclass of JPanel to build
program - Java Beginners
program  create a series as 55555 54444 54333 54322 54321  Hi friend here is ur solution class Series { public static void main(String args[]) { int series=55555; int deduct=1111; int m=1000; int j
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
program - Java Beginners
program  Hello..can u write the following program for me ..thanks 1. Write a program that reads three numbers and an integer n. The program should print the n numbers of a series where each integer in the series is the sum
Chart Series Class in Flex4
Chart Series Class in Flex4: The chart series classes are used for render a data in a chart control. The series classes are used mx.charts.chartClasses.Series class package. All series classes are subclasses of this package. Every
multithreaded program help!!!!
multithreaded program help!!!!  Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three
Find sum of series
Find sum of series This section illustrates you how to find the sum of n terms of the series using recursion. For this purpose, we have created a recursive function that takes the parameter 'n' up to which the sum of the series
Need a java program
series.   for(int j=1;j<=5;j++) { int i,a,b,c; a=1;b=1;int n=5; System.out.print("fibonicci series is " + a +" " + b... i,a,b,c; a=1;b=1;int n=5; System.out.print("fibonicci series
program - Java Beginners
program  take the value of x,y, and a then calculate and print the sum of the following series: x1/y2 + x2/y4 + x3/y6......20 terms.... actually the numbers after x and y are exponents...like x to the power 1 / y
Messages Brokers,MQ Series,TIBCO - Java Beginners
Messages Brokers,MQ Series,TIBCO  Any one explain where we use these technologies "Messages Brokers","MQ Series","TIBCO". In the above 3 technologies which one is better for me. i did SCJP1.5 and i am working on Struts
Java Program - Java Beginners
a program using doâ?¦..while loop to calculate and print the first m Fibonacci numbers. (Hint : After the first two numbers in the series, each number is the sum... void main(String[] args) { System.out.println("*****Fibonnaci Series
program - Java Beginners
program  create a series as 0, 3, 8, 15 ,24 ,35.....n terms?  class Series { public static void main(String[] args) { int n,y; y = 0; System.out.println(y); for(n=1;n<8;n++) { y=y+((2*n)+1
java program - Java Beginners
for "clear".after pressing show button a fibonacci series will appear where each element of fibonacci series will appear 1fter 10 seconds.after pressing clear it will b cleared.the program should b done onlu using java applet but not with swing
java program - Java Beginners
java program  I have to make two radio buttons where one to show and one for clear.when u ser choose show button a fibonacci series will appear and on choosing clear the page will b cleared.how can i implement this?i cannot take