View Single Post
  #1 (permalink)  
Old 08-01-2007, 06:57 AM
mary mary is offline
Member
 
Join Date: Jul 2007
Posts: 51
mary is on a distinguished road
problems with array index
I have a vector
I try to print out the smallest number After compiling I get this messege: Arrays index is out of bound Exception.
what's the problem?
Code:
class VectorTest{ public static void main(String[]args){ int smallestvalue=Integer.MAX_VALUE; int lastvalue; int currentvalue; int []v={5,3,6,0}; int i=0; while(i>=0){ currentvalue= v[i+1]; lastvalue= v[ i ]; if(current>last){ smallestvalue=lastvalue; }else{ smallestvalue=currentvalue; } i++; } System.out.println(smallest); } }
Reply With Quote
Sponsored Links