|
-
java problem
[code]
Hi!
I have a vector ( int []v={4,13,6,2}
I try to print out the smallest number(2). After compiling I get this messege: Arrays index is out of bound Exception.
I try also to print out the vector like this:2,4,6,13.
How do I solve these problems.
------------------------------------------------------
class MyVector{
public static void main(String[]args){
int smallest=Integer.MAX_VALUE;
int last;
int current;
int []v={4,13,6,2};
int i=0;
while(i>=0){
current= v[i+1];
last= v[ i ];
if(current>last){
smallest=last;
}else{
smallest=current;
}
i++;
}
System.out.println(smallest);
}
}
[code]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks