Results 1 to 2 of 2

Thread: Help with Computer Science Java

  1. #1
    Sep 2009

    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
    Aug 2009
    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: Nov 7th 2011, 04:05 PM
  2. computer science problem
    Posted in the Algebra Forum
    Replies: 2
    Last Post: Mar 19th 2010, 05:16 PM
  3. Computer Science
    Posted in the Advanced Math Topics Forum
    Replies: 2
    Last Post: Aug 7th 2009, 05:06 PM
  4. Computer science: Functions help
    Posted in the Pre-Calculus Forum
    Replies: 3
    Last Post: Jan 27th 2009, 12:59 AM
  5. Calculus on science computer
    Posted in the Calculus Forum
    Replies: 2
    Last Post: Jul 18th 2007, 07:10 PM

Search Tags

/mathhelpforum @mathhelpforum