arunnambiar1994 Active member
| Subject: HELP ME IN THIS ARRAY PROGRAMME Fri Jan 30, 2009 6:09 pm | |
| PLEASE HELP ME WHY THERE IS A ERROR MESSAGE"ArrayIndexOutOfBounds:-1"WHILE I RUN THE PROGRAMME ON MY COMPUTER import java.io.*; class Array_Starter_0___Program_25_ { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ar[]=new int[10]; int i; System.out.println(" Enter 10 Numbers "); for(i=0;i<10;i++) { ar[i]=Integer.parseInt(br.readLine()); } int n=ar[0]; for(i=0;i<10;i++) { ar[i-1]=ar[i]; } ar[i-1]=ar[0]; System.out.print(" Output "); for(i=0;i<10;i++) { System.out.print(ar[i]); } } } |
|
Anu..i luv icse...:) Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Fri Jan 30, 2009 6:38 pm | |
| its because you have given ar[i-1]=ar[i] so, when i=0, i-1=-1; which is not in the index oof -1(you have given only from 0 to 9 as index of array ar. so, its Array index out o bounds, it means that the given value is beyond the boundary of the array. |
|
arunnambiar1994 Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Fri Jan 30, 2009 10:19 pm | |
| HOW TO SOLVE THE PROBLEM |
|
Anu..i luv icse...:) Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Sat Jan 31, 2009 4:13 pm | |
| what is the question? this program is to do what? |
|
arunnambiar1994 Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Sat Jan 31, 2009 8:12 pm | |
| I EXPECTED THIS QUESTION FROM YOU! THIS WAS OUR COMPUTER PRACTICAL AND IT RAN IN SOME COMPUTER AND DID NOT RUN IN SOME COMPUTER.IS THIS THE PROBLEM OF THE COMPUTER OR THE CODE.OUR TEACHER IS STRANGE AND MAM GAVE THE PROCESS- for(i=0;i<10;i++) { ar[i-1]=ar[i]; } ar[i-1]=ar[0]; MAM TOLD SIZE 10 OF ARRAY AND FIND THE AIM OF THE PROGRAMME. WE FOUND OUT THAT THE AIM WAS TO PRINT THE NUMBER ONE LESS THAN THE NUMBER INPUTED. WHERE IS THE PROBLEM!!! |
|
Anu..i luv icse...:) Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Mon Feb 02, 2009 3:21 pm | |
| ok...i'll tell u wat i have understood.... the program is to accept 10 values in an array, and then print one less than the entered values of the array......right? then it should be.... import java.io.*; class Array_Starter_0___Program_25_ { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ar[]=new int[10]; int i; System.out.println(" Enter 10 Numbers "); for(i=0;i<10;i++) { ar[i]=Integer.parseInt(br.readLine()); } System.out.print(" Output "); for(i=0;i<10;i++) { a[i]=a[i]-1; System.out.print(ar[i]); } } } check if this comes right/.. |
|
arunnambiar1994 Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Mon Feb 02, 2009 4:52 pm | |
| THANK YOU IT WORKED!!! |
|
ambili Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Mon Feb 02, 2009 7:15 pm | |
| that's right |
|
arunnambiar1994 Active member
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME Thu Feb 05, 2009 5:13 pm | |
| OK OK O K OK OK OK |
|
Sponsored content
| Subject: Re: HELP ME IN THIS ARRAY PROGRAMME | |
|
|
|