Results 1 to 11 of 11
Thread: Stupid Array are Stupid.
- 04-13-2012, 02:40 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Stupid Array are Stupid.
A Java program using single dimensional array. Have a list of 10 numbers and fetch a value based on the index.
A Java program to sort these numbers in ascending order using a bubble sort: 16, 100, 205, 8, 1, 3, 2, 5, 7, 6, 15, 10, 14
A Java program to find the value 45.3 from this list ={-3,10,5,24,45.3,10.5} using the binary search method.
I need some help with the bubble methods and the binary methods.
- 04-13-2012, 02:47 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Need some help with Arrays
There is a method called Collections.sort() that may be used to sort arrays of enumerable objects - just deliver an ArrayList<int> of your numbers to it:
Here is an example: Perform Binary Search on Java ArrayList Example | Java Examples - Java Program Sample Source Code
- 04-13-2012, 03:02 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
- 04-13-2012, 03:08 PM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Need some help with Arrays
Did you try and think a bit about it?
Did you try to replace Collections.sort with Arrays.sort or use ArrayList.toArray()?
- 04-13-2012, 03:40 PM #5
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Stupid Array are Stupid.
Trying to do a stupid bubble sort but this shit wont work.Java Code:package OOP; public class Array2 { int i, j, t; public static void main(String [] args){ int a[] = {16, 100, 205, 8, 1, 3, 2, 5, 7, 6, 15, 10, 14}; System.out.println("Before sort:"); for(int i = 0; i < a.length; i++){ System.out.println(a[i]); } System.out.println("Accending order:"); for(j = 1; j< a.length; j++){ for(i = 0; i<a.length - j; i++){ if (n[i] >n[i+1]){ int temp = n[i]; n[i] = n[i+1]; n[i +1] = temp; } } } } }
-EDIT: FIXEDLast edited by Army; 04-13-2012 at 03:52 PM.
- 04-13-2012, 03:49 PM #6
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Stupid Array are Stupid.
Pseudocode for bubblesort:
Guess you went the wrong way down - hope that helps... ;)Java Code:bubbleSort(Array A) for (n=A.size; n>1; n=n-1) for (i=0; i<n-1; i=i+1) if (A[i] > A[i+1]) A.swap(i, i+1)
- 04-13-2012, 03:57 PM #7
Re: Stupid Array are Stupid.
Please print the results of your sort. Use the Arrays toString() method to format the array for printing.
S.o.println("array=" + Arrays.toString(<THENAMEOfARRAY>));If you don't understand my response, don't ignore it, ask a question.
- 04-13-2012, 04:32 PM #8
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Binary Search Method
A Java program to find the value 45.3 from this list ={-3,10,5,24,45.3,10.5} using the binary search method.
Everything I do come up in errors, can someone just send me something that I can take to make this easier.
- 04-13-2012, 04:44 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Binary Search Method
That list is not in any particular order; a prerequisite for the binary search algorithm.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-13-2012, 04:55 PM #10
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Binary Search Method
This is the third thread you have opened today on that topic... maybe you should rethink this behaviour and solve it in your original thread.
- 04-13-2012, 06:51 PM #11
Re: Binary Search Method
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Stupid mistake, maybe?
By knox in forum New To JavaReplies: 1Last Post: 11-10-2011, 08:39 AM -
I need an idea with something really stupid
By blf_titi in forum Threads and SynchronizationReplies: 2Last Post: 10-27-2010, 03:24 AM -
Stupid error
By dewitrydan in forum Java AppletsReplies: 3Last Post: 08-09-2010, 01:29 PM -
incredibally stupid....
By tek0011 in forum New To JavaReplies: 7Last Post: 11-26-2009, 09:35 AM -
a really stupid question
By SwinGirl in forum NetBeansReplies: 10Last Post: 06-25-2008, 09:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks