DJ1one's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
New Members
Active Posts:
13 (0.02 per day)
Joined:
05-October 12
Profile Views:
156
Last Active:
User is offline Dec 11 2012 11:07 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   DJ1one has not set their status

Posts I've Made

  1. In Topic: Help on displaying select sums for summation

    Posted 11 Dec 2012

    View PostGregBrannon, on 11 December 2012 - 07:26 AM, said:

    As you're computing the terms from 1 to 10, you could use an if statement to print only those needed:
    if ( i > 1 && i < 8 || i == 10 )
    {
        // print a line of results
    }
    


    Thanks! That's exactly what I needed, i forgot about the && and ||s of an if function. Except I applied this to the sums of the summation, rather the number of terms.

    I got my program to work perfectly with this code:
    public class Lab8s {
    
    	//summation method
    	public static double S(int n) {
    		double result = 0;
    		double sum = 0;
    		for (int i = 1; i <= n; i ++) {
    			sum += (1.0 / i);
    		}
    
    		return sum;
    	}
    
    	//main method
    	public static void main(String[] args) {
    		System.out.println("term\t\tsum");
    		for (int i = 1; i <= 13000; i++)
    			if(S(i)>1.9&&S(i)< 2.1||S(i)>2.9&&S(i)<3.0||S(i)>3.99&&S(i)<4.0||S(i)>4.99&&S(i)<5.0||S(i)>6.999&&S(i)<7.0||S(i)>9.9999&&S(i)<10.0)
    				System.out.println(i + "\t\t" + Math.round(S(i)));
    	}
    
    }
    


    And i got the output
    term		sum
    4		2
    10		3
    30		4
    82		5
    615		7
    12366		10
    
    


    My question is, is there any way to trim down the If-Function and still produce to the same output?
    If-fuction:
    if(S(i)>1.9&&S(i)< 2.1||S(i)>2.9&&S(i)<3.0||S(i)>3.99&&S(i)<4.0||S(i)>4.99&&S(i)<5.0||S(i)>6.999&&S(i)<7.0||S(i)>9.9999&&S(i)<10.0)
    				System.out.println(i + "\t\t" + Math.round(S(i)))
    


    Again, the instruction are to:

    Write a recursive method to compute the sum of following series:

    S(i) = 1 + + 1/3 + .. + 1/i

    Test your program to determine how many terms must be added for the sum to grow to: 2, 3, 4, 5, 7, and 10 ?
  2. In Topic: Help on displaying select sums for summation

    Posted 11 Dec 2012

    View PostSheph, on 10 December 2012 - 10:10 PM, said:

    Define the summation method... or in other words, what is the expected output?


    Summation: S(i) = 1 + 1/2 + 1/3 + ... + 1/i + 1

    The expected output would be

    i		S(i)
    		2
    		3
    		4
    		5
    		6
                    7
                    10
    


    Whatever goes under i would obviously be the "i" term.
  3. In Topic: Error: Exception in thread "main" java.lang.NoSuchMethodError:

    Posted 20 Nov 2012

    Can I get a link to javadoc ?
  4. In Topic: Error: Exception in thread "main" java.lang.NoSuchMethodError:

    Posted 20 Nov 2012

    View Postg00se, on 20 November 2012 - 06:46 AM, said:

    Sorry! Forget my comments on the count issue. I've been rather dozy in this question ;)/>


    :D I appreciate the help from both of you guys, thanks. I'm trying to adjust this Scanner issue, i removed the quotation marks but know it wont allow me to compile the program because of the 'cannot find symbol' error.
  5. In Topic: Error: Exception in thread "main" java.lang.NoSuchMethodError:

    Posted 20 Nov 2012

    Oh so it does actually get the data from that text file?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

DJ1one hasn't added any friends yet.

Comments

DJ1one has no profile comments yet. Why not say hello?