Results 1 to 6 of 6
 10192013, 01:34 AM #1Member
 Join Date
 Oct 2013
 Posts
 8
 Rep Power
 0
How to find an even and odd position in an int/long?
Hello,
For example (long input):
7892472304
4, 3, 7, 2, 8 are in the odd positions, while 0, 2, 4, 9, 7 are in the even positions.
What I'm trying to do is do something to the ones in even position and something else for the ones in the odd position. I have used mod 10 to extract each number, but I am not sure how I can check if something is in even or odd position.
Thank you for your time.
 10192013, 03:47 AM #2Member
 Join Date
 Oct 2013
 Posts
 7
 Rep Power
 0
Re: How to find an even and odd position in an int/long?
a simmple boolean will let u pick switch between the to the first number will always be odd assumeing your starting from the back then once you do what you want to odd switch your (isodd) boolean to false
ie
while (a <=NUMLENGHT)
{
//cuts and ads the last number on the string to cSum and switches to other equation
if (isEven==false){
cardNum=cardNum/10;
isEven=true;
a++;
}
//preforms the slightly more complicated math as asked for then switchs back to other equation
else{
oTen=(cardNum%10)*2;
if(oTen>=10){
oTen=oTen9;}
cardNum=cardNum/10;
isEven=false;
a++;
}
 10192013, 03:48 AM #3Member
 Join Date
 Oct 2013
 Posts
 7
 Rep Power
 0
Re: How to find an even and odd position in an int/long?
i cut part of the code out incase were in the same class cause if i do your home work now youll be fucked for the finals / later assinment
 10192013, 06:35 PM #4Member
 Join Date
 Oct 2013
 Posts
 8
 Rep Power
 0
 10192013, 06:59 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
 10202013, 06:00 AM #6Member
 Join Date
 Oct 2013
 Posts
 8
 Rep Power
 0
Re: How to find an even and odd position in an int/long?
Thanks for the reply. I did it in a different way. What I did was set a condition inside the mod 10 loop, like:
if (count%2 == 0)
//calculations
else
//calculations
count++
So everytime it goes through the loop, the ifcondition alternates between every other digit. I hope this helps anyone.
Similar Threads

[find out the lucky position to survive]will you help me please !
By Digital.Oct in forum New To JavaReplies: 4Last Post: 03312011, 02:29 PM 
Find index position of every word in a String
By pentace in forum New To JavaReplies: 6Last Post: 06282009, 09:26 PM 
get position in string from caret position
By helloworld111 in forum AWT / SwingReplies: 5Last Post: 02192009, 02:36 AM
Bookmarks