1-2+5-10+17-26 sum the series 1 Answer(s) 3 years and 5 months ago
Posted in : Java Beginners
1-2+5-10+17-26 sum the series
View Answers
January 9, 2010 at 7:36 PM
Hey Ankit, Try the following code.
public class SumOfSeries3 {
/** * @param 'series' holds the series need to be printed */ StringBuffer series = new StringBuffer(); public static void main(String[] args) { SumOfSeries3 obj = new SumOfSeries3(); int start = 0; int end = 7; int result = obj.performOperation(start, end); obj.modifySeries(); System.out.println(""+obj.series+result); }
/** * @param 'j' is used to know whether a no. is odd or even. * @param 'evenNums' holds all the even numbers (i.e., all the negative numbers) * @param 'oddNums' holds all the odd numbers (i.e., all the positive numbers) */ public int performOperation(int begin,int end){ int firstNumOfSeries = (begin*begin)+1; int oddNums = firstNumOfSeries; int evenNums = 0; int temp = 0; int j = 0; series.append(firstNumOfSeries).append('-'); for(int i=begin+1;i<=end;i++){ temp = (i*i)+1; series = series.append(temp); if(j%2 == 0){ evenNums = evenNums + temp; series.append('+'); }else{ oddNums = oddNums + temp; series.append('-'); } j++; } return(oddNums - evenNums); } /** * This method modifies the series that need to be printed * by replacing the last character of the String Buffer '+' with '=' */ public void modifySeries(){ int length = series.length(); series.deleteCharAt(length-1); series.append('='); } } ------------------- o/p: 1-2+5-10+17-26+37-50=-28
Regards, javaquest2010
Related Pages:
1-2+5-10+17-26 sum the series - Java Beginners 1-2+5-10+17-26sum the series 1-2+5-10+17-26sum the series .../p:
1-2+5-10+17-26+37-50=-28
Regards,
javaquest2010... {
/**
* @param 'series' holds the series need to be printed
*/
StringBuffer
sum of the series sum of the series Program to sum the series
1+1/1!+1/2!+1/3!+....n
series
series s=1/a+2/a^2+2/a^3+3/a^3+.........n
logic is :->
long sum=0;
for(int i=1;i<=n;i++){
sum=sum+i/(math.pow(a,i))
}
System.out.println("sum:"+sum
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
sum
+"+");
}
System.out.print("\nSum of the series : "+sum... java.util.*;
class Series
{
public static void main(String[]args...("The series : 1+");
for(int i=2;i<=n;i++){
s=(s*10)+i
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
Sum of seris Sum of seris Program to find the sum of the following series using a function declaration. sum=x-(xxx)/3!+(xxxxx)/5!-(xxxxxxx)/7!+.....(xx....x)/n!. Where n and x are entered from the keyboard
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 program in Java - Java Beginners Series program in Java Wap to print the series and find the sum:-
1...(begin, end);
obj.MoidfySeries();
System.out.println("Sum of the series...=start;i<=end;i++){
fact = factorial(i);
sum = fact+i;
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
SERIES PROGRAMMING SERIES PROGRAMMING WAP to print the followin series till n terms:
S = 1-4+9-16+25.............n
sum in JTable sum in JTable how to calculate sum from JTable's one field like total
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
Sum of integers Sum of integers A Java program that reads an integer value from the user and displays
i) the sum of all even integers between 1 and the input value, both inclusive.
ii) The sum of all odd integers between 1 and the input
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
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
sum and average of grades sum and average of grades how to print a program which is sum and average of Korean (90), English(85), Mathematics(78), Biology(65), Chemistry(83
Sum of first n numbers Sum of first n numbers i want a simple java program which will show the sum of first
n numbers....
import java.util.*;
public class...=input.nextInt();
long sum=0;
for(int i=1;i<=n;i++){
sum+=i
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
Calculate sum and Average in java
Calculate sum and Average in java How to calculate sum and average...();
int num = Integer.parseInt(data);
int sum = 0;
float avg = 0.0f;
for (int i = 1; i <= num; i++) {
sum = sum + i
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
Sum - JSP-Servlet
the total sum of items from database using Java servlet or Jsp and html form. It should display the affected rows and the total sum of all in a seperate column...,
Sum Into Database
Salary
Sum of positive and negative numbers Sum of positive and negative numbers Hi
if someone could help... the sum of all the positive integers and the sum of all the negative integers.
 ...];
}
}
System.out.println("Sum of positive numbers: "+sum2);
System.out.println
Using sum() in hibernate criteria.
Using sum() in hibernate criteria. How to calculate sum() in hibernate criteria by using projection?
You can calculate sum of any...(employee);
}
}
}
Output:
Hibernate: select sum
sum database column sum database column please i have two columns-col1 and col2, col1... 3
Soap 4
how will i query the database to sum the Items... for you.
select item, sum(quqantity) from `order` group by item
Hibernate criteria sum.
Hibernate criteria sum.
Here, we will introduce you to about the sum() function . It returns
the sum of total value of column.
Syntax :
Criteria... message as shown below:
Hibernate: select sum(this_.fee
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 database colum in java Sum database colum in java please i have two columns-col1 and col2... the database to sum the Items and display output so that it will be like... question what you have asked.
select item, sum(quqantity) from `order` group
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
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
Sum - JSP-Servlet
Sum Hi Guys, thank you all for support for us all. Please I want to sum up from a particular row from the database, get all the rows affected... = con.createStatement();
ResultSet res = st.executeQuery("SELECT SUM(amount) FROM