# Thread: Help with Computer Science Java

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

2. 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.