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.

Re: Rookie Question! Help Appreciated

Then I would say the next step would be to make the code consider all 5 numbers.
How would you do it without a computer?
What steps would you take, specifically. Write down each thing you must do to find the answers yourself. Each number you look at, each number you compare to, etc...
When you have a list of steps organized in a start to finish order, then you can start working on the code.

Re: Rookie Question! Help Appreciated

I am saying do not worry about how "it" will solve the problem. I am asking how YOU would solve the problem.
15 84 20 13 68 43
In reality there are two problems to solve;
1) find the highest number
2) find the lowest number
Work on one problem at a time. How would you find the highest number?

Re: Rookie Question! Help Appreciated

Okay, so far so good.
Have a look at what you have done so far.
First you selected a number, (by default just the first one in line)
Then you compared this number to the next number in line. For this to happen you had to remember which number you were going to compare to the next.
Then you repeat this process for each of the remaining numbers.

-the following still needs to be done-
Somewhere along the way, if a larger number is found, you will have to remember that number instead. When you reach the end of the set of numbers, the number being compared should be the largest. Problem of finding the largest number is solved.

This means you may use a variable like largestNumberSoFar to keep track of the current largest number as you go.
Give it a shot and see what you come up with

Re: Rookie Question! Help Appreciated

Originally Posted by Knighter

Like I know the process, I just don't know what to use, that's my original question

I understand, but no one can write the code for you, you can read about why here.
This exercise is to get you some practice turning a simple process into code so that you can handle a more complicated process. Work on the idea of breaking the problem down into steps that you can turn into code, that is what it is all about. Every detail matters when you tell a computer to do it for you.

--- Update ---

The pseudo code in post #13 does not match what you had in post #9
(As a side note 'number6' is a poor description of what that number is for)
Why are you getting a new number for number6, that should represent the largest number found so far. In post #9 that value was 84, which was the first number in the set, (number1) and not a new number given by the user.

Re: Rookie Question! Help Appreciated

How about this for pseudo code:
(First, the instructions)
after typing 5 integers to then display the largest and smallest one

set up a place to store 5 integers
get 5 integers from the user
set up a place to store the largest integer
give the largest integer variable the value of the first integer.
compare the largest integer variable to each of the remaining numbers in the set (the other 4)
if a larger number is found, replace the largest integer value with the newly discovered larger value, else do nothing
at the end of the set, the value in the largest integer variable will be the largest number given by the user

Re: Rookie Question! Help Appreciated

Yes sort of, your brain works a bit faster than mine with this stuff I'm a 4th year business student trying to self teach myself java hehe, these are some excercises I found online, however no solution or explanations are given but I really want to solve this one. My question is though how to find the largest integer of the 5, I know how to store it etc once its found but how do I find it, I only know how to compare 2 numbers, not 6, for example

Re: Rookie Question! Help Appreciated

( number1 > number2, number3, number4, number5 ) Something like this just does not work
Read over the pseudo code in post #16 again and see if you can follow the idea there. It is just a more detailed description of what you had in post #9
You will have to compare them one at a time like you started to do in the original code.

Re: Rookie Question! Help Appreciated

I like it all the way up to:
largestinteger = input.nextInt()

When you do the test largestinteger < number2, if numbr2 turns out to be the larger, then you would assign the value of number2 to largestinteger
largestinteger = number2;
Then largestinteger would in fact hold the largest integer so far, continue to check number3 and number4.

I was watching both you and jps. I was made aware of spoonfeeding the other day. And now I really see the benefit of leading you to the answer no matter how much you want to give the answer, you got to enjoy the wonderful ah-hah moment.