very simple question
intefer is an integer.
array is a predefined array of intefegers.,
Now, please tell me if this is ok:
array[0] = intefer;
will the first number in array now become intefer ?
I've got this massive error and I can鑤 figure out what's the case...I hope this will solve my problems...
[318 byte] By [
Emira] at [2007-11-26 21:29:32]

Did you allocate the array? as in: array= new int[42]?kind regards,Jos
> intefer is an integer.
>
> array is a predefined array of intefegers.,
What is a "predefined array"?
> Now, please tell me if this is ok:
>
> array[0] = intefer;
It depends on what came before that to define and initialize array.
> will the first number in array now become intefer ?
If you did everything right before that, yes.
> I've got this massive error and I can鑤 figure out
> what's the case...I hope this will solve my
> problems...
It would help if you'd post the actual errors, and more of your code.
When you post code, please use[code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] on the message entry page. It makes it much easier to read.
I believe I did :int[] array = new int[5];
Emira at 2007-7-10 3:10:03 >

> I believe I did :> > int[] array = new int[5];Sure? show us some code please and the actual Exception stack trace.kind regards,Jos
I'm not allowed to post my code :( at least not everything
I guess I did everything right...............
This is what I want to do....I want the program to read three variables from three different files....And I did that, for sure, tested it, it's ok.
Now, I want the computer to bubble sort the files that it has already read from the files and print them to the user from the highest value to the lowest....What I did now is I assigned every entered value in one array (first values entered is array[0],, second array[1], etc)
now this is how I figured I'd bubble sort>
[quote]for (int v=0;x<3;x++){
for (int y=0;y<3;y++){
if (array[y] > array[y+1]){
temp = array[y+1];
arrayf[y+1] = array[y];
array[y]]= temp;}}}
[/quote]
but for some odd reason it does not work. I get this error>
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
how on earth? I-be been struggling with this problem for a souple of hours now, and I need to solve this, because if I do, I've finished my program !
btw about the exception....
catch(IOException io){
System.out.println("Error")
}
Message was edited by:
me
Emira at 2007-7-10 3:10:03 >

its hard to preditct without seeing your whole code. anyway try this. make some changes in your second for loop statement.
for (int y=0;y<3-1-i;y++){
Message was edited by:
fastmike
> I'm not allowed to post my codeThose b*stards! They got to you, too?
> its hard to preditct without seeing your whole code.
> anyway try this. make some changes in your second for
> loop statement.
> > for (int y=0;y<3-1-i;y++){
>
>
> Message was edited by:
> fastmike
but I have that, don't I ?
I can-t post my code :(
Don't ask, rules are rules
anyway, the rest of the code is no problem....I had the program working, but then I figure I need to bubble sort the information read from the files...and then I added arrays and the code above and hell started...
HALP !
(I know I misspelled help)
Emira at 2007-7-10 3:10:03 >

> I guess I did everything right...............Obivously not. But if you won't tell us exactly what you did (that is, by posting your exact code and error message) then it's impossible to give you any help other than general pointers.
> > I guess I did everything right...............
>
> Obivously not. But if you won't tell us exactly what
> you did (that is, by posting your exact code and
> error message) then it's impossible to give you any
> help other than general pointers.
I have posted every thing needed. Even the error message it get! Note that I get that message when running the program, not when compiling
Emira at 2007-7-10 3:10:03 >

> I have posted every thing needed.
Okay. There's nothing in the code you posted that will attempt to access array[5]. And it won't even attempt to access arrayf[5] either -- I don't think you should be working with the two different arrays in your swapping code, but that wouldn't cause the exception you posted.
if you are getting ArrayIndexOutOfBoundsException: 5 that means somewhere you are trying to get index 5 out of your array, which you already said has a size of 5, which means indices go from 0 to 4.
> > > I guess I did everything right...............
> >
> > Obivously not. But if you won't tell us exactly
> what
> > you did (that is, by posting your exact code and
> > error message) then it's impossible to give you
> any
> > help other than general pointers.
>
> I have posted every thing needed.
No, you haven't.
It's starting to sound like this thread: http://forum.java.sun.com/thread.jspa?threadID=536546
> its hard to preditct without seeing your whole code.
> anyway try this. make some changes in your second for
> loop statement.
> > for (int y=0;y<3-1-i;y++){
>
>
> Message was edited by:
> fastmike
OPen your eyes soldier !
> > its hard to preditct without seeing your whole
> code.
> > anyway try this. make some changes in your second
> for
> > loop statement.
> > > > for (int y=0;y<3-1-i;y++){
> >
> >
> > Message was edited by:
> > fastmike
>
> but I have that, don't I ?
>
> I can-t post my code :(
>
> Don't ask, rules are rules
>
> anyway, the rest of the code is no problem....I had
> the program working, but then I figure I need to
> bubble sort the information read from the files...and
> then I added arrays and the code above and hell
> started...
>
> HALP !
>
> (I know I misspelled help)
Open your eyes soldier !
This is what I want to do....I want the program to read three variables from three different files....And I did that, for sure, tested it, it's ok.
Now, I want the computer to bubble sort the files that it has already read from the files and print them to the user from the highest value to the lowest....What I did now is I assigned every entered value in one array (first values entered is array[0],, second array[1], etc)
for (int x=0;x<3;x++){
for (int y=0;y<3;y++){
if (array[y] > array[y+1]){
temp = array[y+1];
arrayf[y+1] = array[y];
array[y]]= temp;} } }
I'm certain that the previous code is ok, since it worked fine before I wanted to sort. I'm having problems sorting the information. Is everything ok with the information I have posted so far?
I'm not trolling! I just cannot post my code... :*(
--
I-ve just read the post....than you for your help, but I still have problems :(
I don-t have anything else that deals with the arrays...ah, thansk anyway
Message was edited by:
Emir
Message was edited by:
Emir
Emira at 2007-7-21 18:19:08 >

> for (int x=0;x<3;x++){
> for (int y=0;y<3;y++){
> if (array[y] > array[y+1]){
> temp = array[y+1];
> arrayf[y+1] = array[y];
> array[y]]= temp;} } }
>
>
What does the for loop with x do ? I don't see the x variable referenced ever.
> > for (int x=0;x<3;x++){
> > for (int y=0;y<3;y++){
> > if (array[y] > array[y+1]){
> > temp = array[y+1];
> > arrayf[y+1] = array[y];
> > array[y]]= temp;} } }
> >
> >
> What does the for loop with x do ? I don't see the x
> variable referenced ever.
I ensured that the loop with the variable y will get executed a couple of time, in order for it to be sure that the data is sorted.
Emira at 2007-7-21 18:19:08 >

the program reads from three files three different variables. They are all stored into the array as array[0].array[1],array[2] etc
Emira at 2007-7-21 18:19:08 >

are you trying to sort one array ?
indeed.
Emira at 2007-7-21 18:19:08 >

Why not call Arrays.sort(array); ? (instead of writing a bubble sort)