# Help With Counter

• February 8th, 2011, 02:59 AM
Catgroove
Help With Counter
I'm trying to make this program check what number is the highest and write it out in that order, not working for me. How would one solve this?

Code Java:

```public class Upg11 { public static void main(String[] args) { int[] tal = new int[5]; System.out.print("Mata in fem heltal: "); tal[0] = Keyboard.readInt(); tal[1] = Keyboard.readInt(); tal[2] = Keyboard.readInt(); tal[3] = Keyboard.readInt(); tal[4] = Keyboard.readInt();   for (int n = 0; n < 5; n++) { int i = 1; if (tal[n] < tal[i]) { int temp = tal[n]; tal[n] = tal[i]; tal[i] = temp; }   }   System.out.println("Talen är " + tal[0] + " " + tal[1] + " " + tal[2] + " " + tal[3] + " " + tal[4]); } }```
• February 8th, 2011, 03:35 AM
DanBrown
Re: Help With Counter
you need to go through certain sorting algos:

• February 8th, 2011, 07:49 AM
KevinWorkman
Re: Help With Counter
Quote:

Originally Posted by Catgroove
I'm trying to make this program check what number is the highest and write it out in that order, not working for me. How would one solve this?

Sorry, but saying "not working for me" is as useful a question as us saying "then make it work" is a useful answer. What's happening? What did you expect to happen? Are you seeing any Exceptions? Strange behavior? Something else?
• February 9th, 2011, 05:21 AM
Catgroove
Re: Help With Counter
Quote:

Originally Posted by KevinWorkman
Sorry, but saying "not working for me" is as useful a question as us saying "then make it work" is a useful answer. What's happening? What did you expect to happen? Are you seeing any Exceptions? Strange behavior? Something else?

I'm trying to make it display the numbers again but the in a size order. Highest first. Currently just shows them without changing positions.
• February 9th, 2011, 07:42 AM
JavaPF
Re: Help With Counter
Look into the Arrays.sort method
• February 9th, 2011, 08:19 AM
kuzhali
Re: Help With Counter
you forget to increament i.i should be increament by 1.
• February 9th, 2011, 09:55 AM
Catgroove
Re: Help With Counter
I tried it before and doesn't work.
• February 10th, 2011, 07:50 AM
KevinWorkman
Re: Help With Counter
Quote:

Originally Posted by Catgroove
I tried it before and doesn't work.

Then make it work. :p