Results 1 to 6 of 6
 10192013, 12: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, 02: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, 02: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, 05:35 PM #4Member
 Join Date
 Oct 2013
 Posts
 8
 Rep Power
 0
 10192013, 05:59 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,292
 Blog Entries
 7
 Rep Power
 24
 10202013, 05: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, 01:29 PM 
Find index position of every word in a String
By pentace in forum New To JavaReplies: 6Last Post: 06282009, 08:26 PM 
get position in string from caret position
By helloworld111 in forum AWT / SwingReplies: 5Last Post: 02192009, 02:36 AM
Bookmarks