By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

Vector help

P: 5
Hi,

I would like to know how to do this
if ((array[i+1] - array[i] == 2) operation with a vector.
I have tried to find out how to do it, but haven't yet succeeded.

-maks
Jan 19 '07 #1
Share this Question
Share on Google+
5 Replies


Ganon11
Expert 2.5K+
P: 3,652
Use the .get() function. It takes an integer argument representing the index of the item you wish to retrieve. For example, array[5] would be myVector.get(5), and array[i + 1] would be myVector.get(i + 1).
Jan 19 '07 #2

Expert 100+
P: 1,510
Hi,

I would like to know how to do this
if ((array[i+1] - array[i] == 2) operation with a vector.
I have tried to find out how to do it, but haven't yet succeeded.

-maks
assuming your vector was something like
Expand|Select|Wrap|Line Numbers
  1.   Vector<Integer> array=new Vector<Integer>();
  2.  
this would work
Expand|Select|Wrap|Line Numbers
  1.  if ((array.elementAt(i+1) - array.elementAt(i)) == 2) System.out.println("is 2"); 
  2.  
Jan 19 '07 #3

P: 5
Thanks for answering..I'll try it later today
Jan 20 '07 #4

10K+
P: 13,264
Thanks for answering..I'll try it later today
Well? Did it work?
Jan 23 '07 #5

P: 5
Yeah, sorry for taking so long, but I've been busy doing several things...
Yes it did work very well. Thanks to all who helped me!

-maks
Jan 23 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.