Results 1 to 2 of 2

Math Help - Help with Computer Science Java

  1. #1
    Newbie
    Joined
    Sep 2009
    Posts
    1

    Help with Computer Science Java

    Hey guys, I'm having real trouble trying to wrap my head around this one...can anyone help me out? here is the problem:

    write a program that takes a set of numbers and determines which are the two smallest.
    Ask the user for the following information,:

    1. A terminating value (real number). The user will enter this value again later, to indicate that he or she is finished providing input.
    2. A sequence of real numbers. Keep asking for numbers until the terminating value is entered.

    Compute and output the smallest and second-smallest real number.

    I'm a beginner soo just the basic code would be awesome!
    Thank you soo much
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Aug 2009
    Posts
    15
    Here's some feasible pseudo code. I can't be more specific because i dont know what programming language you are using.

    main() {

    get the terminating number from the user

    get first number in sequence of real numbers from user

    while (most recently entered number != terminating number) {

    *Note that the most recently entered number may need to have global scope, ie *not* be declared inside the loop. This is so it can be accessed in the while loop's header

    add the real number to an array of some sort
    get the next sequence number

    }

    *Here the terminating number has been entered and the loop has exited.

    *a loop to compare the elements
    lowest = a[i]
    for i = 2 to the length of the array - 1
    if lowest > a[i]
    lowest = a[i]

    *and a second loop to compare to find the second lowest
    secondLowest = a[i]
    for i = 2 to length of array -1
    if (secondLowest > a[i]) && (secondLowest > lowest)
    secondLowest = a[i]


    Output lowest and second lowest here



    So, keep in mind this is only psuedocode, i did it kinda quickly so there might be a small mistake or so. But, it should give you a good idea of what needs to go on to do yoru program. Also keep in mind its not the only solution, and there might be easier and cleaner ways to do this.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Oracles in computer science
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: November 7th 2011, 05:05 PM
  2. computer science problem
    Posted in the Algebra Forum
    Replies: 2
    Last Post: March 19th 2010, 06:16 PM
  3. Computer Science
    Posted in the Advanced Math Topics Forum
    Replies: 2
    Last Post: August 7th 2009, 06:06 PM
  4. Computer science: Functions help
    Posted in the Pre-Calculus Forum
    Replies: 3
    Last Post: January 27th 2009, 01:59 AM
  5. Calculus on science computer
    Posted in the Calculus Forum
    Replies: 2
    Last Post: July 18th 2007, 08:10 PM

Search Tags


/mathhelpforum @mathhelpforum