Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to add the numbers in the following series?

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to add the numbers in the following series?

    class series {
    	public static void main(String args[]){
    		int numerator, denominator;
     
    		numerator = 1;
    		denominator = 1;
     
    		System.out.print(numerator);
     
    		for(int counter=0;counter<=198;counter++){
    			denominator+=1;
    			if(denominator % 2 == 0){
    				System.out.print(" - ");
    			}else{
    				System.out.print(" + ");
    			}
    			System.out.print(numerator+"/"+denominator+" ");
    		}
     
     
    	}
    }
    The series in the program is 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6... -1/200, how would you get the sum of the numbers?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to add the numbers in the following series?

    how would you get the sum of the numbers?
    Use a loop and add the individual terms to a variable.


    Continuation of http://www.javaprogrammingforums.com...igns-java.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Swing Tutorials
    Replies: 11
    Last Post: October 15th, 2013, 10:22 PM
  2. How to add line numbers in Eclipse
    By Brt93yoda in forum Java JDK & IDE Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 11:30 PM
  3. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Code Snippets and Tutorials
    Replies: 10
    Last Post: March 31st, 2011, 05:18 AM
  4. How to add line numbers in Eclipse
    By Brt93yoda in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: August 12th, 2010, 11:03 AM
  5. Generate prime numbers within fiboncacci series?
    By Manish87 in forum Algorithms & Recursion
    Replies: 5
    Last Post: August 7th, 2010, 12:24 PM