Series program in Java

Series program in Java

Wap to print the series and find the sum:-
1+2+4+9+28+125





My email-id is:-
[email protected]
View Answers

January 8, 2010 at 2:16 AM

Hi,
Try This.

public class SumOfSeries {

/**
* @param 'begin' holds the start of the series
* @param 'end' holds the end of the series
* @param 'series' holds the series need to be printed
*/
StringBuffer series=new StringBuffer();
public static void main(String[] args) {
int begin = 0;
int end = 5;
SumOfSeries obj = new SumOfSeries();
int result = obj.Sum(begin, end);
obj.MoidfySeries();
System.out.println("Sum of the series from "+begin+" to "+end+" : "+obj.series+result);
}

public int factorial(int num){
int temp=1;
if(num==0)
return 1;
for(int i=num;i>0;i--)
{
temp = temp*i;
}
return temp;
}

public int Sum(int start, int end){
int sumOfSeries=0;
int fact=0;
int sum = 0;
for(int i=start;i<=end;i++){
fact = factorial(i);
sum = fact+i;
series = series.append(sum).append('+');
sumOfSeries = sumOfSeries + sum;
}
return sumOfSeries ;
}

/**
* This method modifies the series that need to be printed
* by replacing the last character of the String Buffer '+' to '='
*/

public void MoidfySeries(){
int index = series.lastIndexOf("+");
series.setCharAt(index, '=');
}
}

Regards,
javaquest2010









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
java programming:generating series
java programming:generating series  WAP to print series: | + || + ||| + |||| + .......... n terms
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
series
series  series 2-4+6-8+..............-20
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
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
printing java series
printing java series  * *** ***** ******** ***** *** *   Post the format properly
java programming:generating series
java programming:generating series  1234554321 1234 4321 123 321 12 21 1 1   Here is a java code that displays the following pattern 1234554321 1234 4321 123 321 12 21 1 1 class Pattern
java programming:generating series
java programming:generating series  12345 1234 123 12 1 1 12 123 1234 12345   Here is a code that displays the following pattern: 12345 1234 123 12 1 1 12 123 1234 12345 class Pattern { public
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
java program
java program  hi friends how to make a java program for getting non prime odd numbers in a given series
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
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
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
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
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
1-2+5-10+17-26 sum the series - Java Beginners
{ /** * @param 'series' holds the series need to be printed */ StringBuffer series = new StringBuffer(); public static void main(String[] args...; series = series.append(temp); if(j%2 == 0){ evenNums
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
Fibonacci series in java
Fibonacci series in java In this section you will learn about fibonacci number in java.  Fibonacci number or Fibonacci sequence are the number... value proceeding it. Here is the code for Fibonacci program: import
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
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
Maven dependency for com.intersult - series version 1.1 is released. Learn to use series version 1.1 in Maven based Java projects
( com.intersult - series version 1.1 ) in their Java project if it is based on Maven... to use  com.intersult - series version 1.1 in Java projects. Follow...Maven dependency for  com.intersult  - Version 1.1 of series
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 - 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
java program for
java program for   java program for printing documents,images and cards
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
java program
java program  write a program to print 1234 567 89 10
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
java program
java program  write a program to create text area and display the various mouse handling events
java program
java program  Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results

Ads