I'm trying to write a program that prints out the largest and smallest of four numbers that are inputted using a JOptionpane, but I cannot figure out how to sort out the integers with if and if else statements. Anyone have any advise?
- 3 Contributors
- forum2 Replies
- 12 Views
- 8 Years Discussion Span
- comment Latest Post by WargRider
NormR1 563
You need to figure out your logic using something like a flowchart on a piece of paper. Or try pseudo code.
Once you get your logic worked out, then worry how to implement your logic.
Can you do your comparisons as the numbers are entered or must you wait until you have all 4.
If your assignment limits you to using 4 separate variables and if / else if statements? That makes for a lot of comparisons.
Edited
by NormR1: n/a
WargRider 10
NormR1 is definitely correct. But on top of his suggestions, let me add to this some code. It is not the SOLUTION, but it what you need to find one :). The 4 numbers that you get, if you know you will get 4, do this:
int[] nums = new Int[4];
//num[0] = one joption pane input here
//num[1] = one joption pane input here
//num[2] = one joption pane input here
//num[3] = one joption pane input here
Use a for loop to go through the _length_ (hint hint) of the array, remember arrays start at index 0, not 1, this is not REGULAR counting per say. Good luck ;) . :O and use ONE integer and figure out IF one number is larger then the previous, store that number in the one int, and in the end you will have your number. If you desperately need code, I can give it to you, but try yourself, I have already given too much :) :D