Help needed for sorting an array using sortOrder

Sorting an array using sortOrder into ascending order

Page 1 of 1

3 Replies - 974 Views - Last Post: 26 April 2009 - 08:51 AM Rate Topic: -----

#1 zanyrogue  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 16-January 09

Help needed for sorting an array using sortOrder

Post icon  Posted 26 April 2009 - 08:31 AM

Hi all,

I'm trying to sort an array into ascending order using sortOrder but i'm not having much luck. Can anyone help? Where is the code going wrong? It's throwing the following error

\Ascending.java:4: invalid method declaration; return type required
public static sortOrder()
^
1 error

Tool completed with exit code 1


class Ascending
{
	//public static void main (String [] args)
	public static sortOrder()
	{

	int [] c = {9,8,4,2,7,1,6,3,5};


	for (sortOrder c : sortOrder.values())
		System.out.println(c);

	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Help needed for sorting an array using sortOrder

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help needed for sorting an array using sortOrder

Posted 26 April 2009 - 08:33 AM

Well this is basic method name calling. You need to give it a return type.
It doesnt look like it is supposed to return anything so your would be void
Always needs one, if nothing then void, if return an int then int.
public static void sortOrder()

Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#3 zanyrogue  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 16-January 09

Re: Help needed for sorting an array using sortOrder

Posted 26 April 2009 - 08:43 AM

View PostFuzzyness, on 26 Apr, 2009 - 07:33 AM, said:

Well this is basic method name calling. You need to give it a return type.
It doesnt look like it is supposed to return anything so your would be void
Always needs one, if nothing then void, if return an int then int.
public static void sortOrder()

Hope this helps!


Yep that helped.
I now have this error. I've had this problem before with bubbleSort which I still haven't solved yet.

\Ascending.java:11: cannot find symbol
symbol : class sortOrder
location: class Ascending
for (sortOrder c : sortOrder.values())

^
\Ascending.java:11: cannot find symbol
symbol : variable sortOrder
location: class Ascending
for (sortOrder c : sortOrder.values())
^
2 errors

Tool completed with exit code 1
Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help needed for sorting an array using sortOrder

Posted 26 April 2009 - 08:51 AM

Have to use a for loop traditional one. Here is an ineffecient bubble sort (there can be a effecient one but easier to type the unefficient one)

int temp;
for(int i =0; i<c.length; i++)
   for(int x = 0; x<c.length-1; x++)
		if(c[x] > c[x+1])
		   {temp = c[x];
			 c[x] = c[x+1];
			 c[x+1] = temp;
			}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1