Detecting even and odd numbers

Hi, I'm drawing a series of rectangles using AS3, and need
every alternate one to be lighter... I'm using a switch statement
currently, with a variable counting the number of rectangles and
case 1, case 2, case 3, etc.
Is there a formula or some way of telling whether there is an
even or odd number of rectangles so my switch statement can just be
case even:, case odd: ? The way I have it is fine for 10 or so
rectangles but I'd rather make it more expandable.
Would appreciate any suggestions

% is a modulo operator that finds a remainder of a division.
9%2 = 1, 9%4 = 1, but 9%3 = 0.
In the case of odd/even numbers one can look at it as that an
even number that leaves no remainder when divided by 2 and odd
number is a number that leaves remaining 1 when divided by
2.

Similar Messages

  • Add Even and Odd Numbers

    I have a programming assignment that needs to read a set of integers and then finds and prints the sum of the evens and sum of the odds.
    I know how to find out which numbers are odd and even, I just can't figure out how to add up the evens and odds. Say a set of 10 integers is inputted, how can they be added up after it is determined if they are even or odd?

    Here is my code after the tip from student... It compiles but once ran it doesn't do anything after the integers are put in.
    import java.util.*;
    public class EvenOddIntegers {
        static Scanner console = new Scanner(System.in);
        static final int limit = 10;
        public static void main(String[] args) {
             int number = 0, limit = 0, sumEven = 0, sumOdd = 0;
             int odds = 0;
            int evens = 0;
             System.out.print("Enter ten positive integers: ");
             while (limit <= 10)
                  number = console.nextInt();
             if (number % 2 == 0)
                  sumEven += number;
             else if (number % 2 != 0)
                  sumOdd += number;
             System.out.println("Sum of even numbers is " + sumEven + ".");
             System.out.println("Sum of odd numbers is " + sumOdd + ".");
    }

  • Random number generator. Even and odd numbers

    I have a problem.
    I have a random number generator, it goes from 0 to 20, I need to have two indicators, one will show how many numbers are pairs, and how many are not.
    I tried to use the decimated 1D array, but since those numbers are random, it doesn´t work for me. I´m new with LabView, and I don´t know if there is some other way to make it work, I need some help, especially with some examples.
    Thank you so much.
    Solved!
    Go to Solution.

    RavensFan wrote:
    Spoiler (Highlight to read)
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Haha I lost sight of the fact that he was looking for the amount off odds and evens.  Good one.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Split and add Even and odd numbers

    Hi All,
    I got a seven digit number any number say for example (6581231). Now i need to add even number and odd number separately.
    Output should be
    6 + 8 + 2 = 16
    5 + 1 + 3 + 1 = 10
    Thanks
    S

    Assuming the number is always 7 digits one way to do this would be:
    Data: string(7) type c,
             num type i.
             Nmod type i.
    **move the number to a string.
    Move num to string.
    split into 7 individual chars.
    Num1 = string+1
    Num2 = string+2.
    Num3 = string+3
    Etc…
    divide each by 2 and find remainder
    Nmod = num  mod 2.
    if remainder is 0, number is even
    If nmod = 0.
    Number is even.
    Else.
    Number is odd.
    Endif.

  • How to display even and odd number ranges between two given inputs.

    Hi Every one,
    I am just started my career in sap abap and trying to find the solution for this.
    I am trying to display number range using select options, but I am getting an error "Memory low leave the transaction before taking a break".
    Example: when I give two number 2 and 10 , it should display set of all even and odd numbers in that range.
    Below is the code logic that I am using:
    data: a type i,
             b type i,
             c type i,
             d type i,
             num type i.
    select-options: in for num.
    a = inp-low.
    b=inp-high.
    c = inp-low mod 2.
    d = inp-high mod 2.
    while a <=b and c = 0.
    write: "even numbers:', a.
    b = a + 1.
    endwhile.
    while a <=b and c <> 0.
    write: "odd numbers:', b.
    b = a + 1.
    endwhile.
    Any help will be much appreciated.

    This is your logic...changed:
    data: a type i,
              b type i,
              c type i,
              d type i,
              num type i.
    data: even type i,
           odd  type i.
    select-options: in for num.
    a = in-low.
    b = in-high.
    c = a mod 2.
    if c is INITIAL. "It measn a is even
       even = a.
       odd  = a + 1.
    else.
       odd  = a.
       even = a + 1.
    endif.
    * Even
    a = even.
    while a <= b.
       write: / 'even numbers:', a.
    *  b = a + 1.
       a = a + 2. "The next even number
    endwhile.
    * Odd
    a = odd.
    while a <= b .
       write: / 'odd numbers:', a.
       a = a + 2. "The next odd number
    endwhile.

  • Anyone know how to select only even or odd numbered files in lightroom?

    Anyone know how to select only even or odd numbered files in lightroom? I need to reduce the quantity of images in my timelapse sequence and this would help me greatly since there are 8250 images and doing this maually would be tediuos and make me want to kill myself.... : )

    Do this.
    If they are jpegs, use .jpg instead of CR2
    Be sure to save this as a preset, as you WILL need it again. Mine is named "select even CR2", that is why it says that in the upper right.

  • How to work even and odd number query

    Plz explain how below worked even and odd query
    2 ) why used subquery after from and which time we can use(what time of out put)
    even
    select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
     WHERE d.row %2=0   
    odd
    select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
     WHERE d.row %2=1

    Row_Number function returns the sequential number of a row
    (By using partition of a result set, starting at 1 for the first row in each partition)
    >> why used subquery after from and which time we can use(what time of out put)
    When we need sequntial numbers, we can use row_number function. Put it into derived table and use this derived table after FROM clause (Same way it is used in your query)
    CREATE TABLE stud_Enrollment (
    grno int,
    stud_id int,
    stud_name varchar(20)
    INSERT INTO stud_Enrollment
    VALUES (101, 511, 'Dheeraj'), (112, 521, 'Vaibhav'), (132, 522, 'Lalit'), (124, 564, 'Amogh'), (143, 598, 'Sushrut')
    SELECT * FROM stud_Enrollment
    -- Result of your table
    --grno stud_id stud_name
    --101 511 Dheeraj
    --112 521 Vaibhav
    --132 522 Lalit
    --124 564 Amogh
    --143 598 Sushrut
    -- Now we need to find out the rows which are at even position, ie row should be at position of 0,2,4,6,8 etc..
    -- But we don't have sequential number here in your table result
    -- So we can create one new column by using row_number function
    SELECT
    ROW_NUMBER() OVER (ORDER BY stud_id) AS row, --> additiona "row" column
    grno,
    stud_id,
    stud_name
    FROM stud_Enrollment
    -- We got "row" column in below output
    --row grno stud_id stud_name
    --1 101 511 Dheeraj
    --2 112 521 Vaibhav
    --3 132 522 Lalit
    --4 124 564 Amogh
    --5 143 598 Sushrut
    -- Now above table is used after FROM clause. It uses row column in WHERE part
    SELECT
    FROM (SELECT
    ROW_NUMBER() OVER (ORDER BY stud_id) AS row,
    grno,
    stud_id,
    stud_name
    FROM stud_Enrollment) d
    WHERE d.row % 2 = 0
    --row grno stud_id stud_name
    --2 112 521 Vaibhav
    --4 124 564 Amogh
    -Vaibhav Chaudhari

  • Counting even and odd values

    Is there another way to count even and odd number than this one
    private static int countEvenOrOdd(int[] array, boolean countEvenNumbers){
              int count = 0;
              int remainderRequired = (countEvenNumbers ? 0 : 1);
              for(int i = 0; i < array.length; ++i){
                   if(array[i] % 2 == remainderRequired){
                        ++count;
              return count;
         }

    > I like hacking ;-) Have a look at this: ...
    Jos, you forgot the method for counting both:int countOddsAndEvens(int[] array) {
    return (countOdds(array) + countEvens(array));
    } ; )Yep, you're right, and for completeness reason I'd like to add the following:int countOthers(int[] array) {
       return array.length-countOddsAndEvens(array);
    }And for those junit maniacs:boolean testCounters(int[] array) {
       return countOddsAndEvens(array)+countOthers(array) == array.length;
    }btw, the moment I posted my previous reply I realized that I could've done better:int countOdds(int[] array) {
       int c= 0;
       for (int i= 0; i < array.length; c+= array[i++]&1);
       return c;
    }kind regards,
    Jos ( <-- never has to maintain others' code ;-)

  • Zero bleed at inside page on even and odd master pages

    Hello guys!  Going directly to my question would be how to apply bleed option specifically on inside pages when working with individual master pages for master and facing pages on the main document. The thing is when I've set no bleed on inside on my Document Setup it has applied on my even and odd master pages (remembering I have individual master pages set on my document). I am not sure if I was clear enough but I keep it open for eventual comments and so on.  Thank you.

    Ok Peter. Thank you! I am posting some screen shots to help understanding.

  • Using Acrobat 9.5.5, I scanned a catalog in several segments, to merge later. How do I reverse the order of pages of the back side (odd) pages, and can I renumber each set as even numbers only and odd numbers only?

    I scanned a catalog for my archive - double sided pages of course.
    It was easy enough to scan the front pages first (odd numbers, 1-3-5) , in several sets of 30 pages, therefore several separate pdfs.
    Then I scanned the back side (even numbers 2-4-6) pages but in their natural reverse order, rather than manually reordering all 300 pages.
    Now I need to reorder the even pages which are naturally in reverse page number order (300-298-296...)
    and I need to renumber all of the pages as only odd or even numbers - set 1: pages 1-3-5-7... Set 2: 2-4-6-8...
    Then I can merge everything into one pdf.
    How can I reverse the page order?
    How can I renumber pages as only even or only odd numbers?
    Anyone have these solutions?  I don't use much of acrobats features, but it seems to be a pretty basic demand to be included. I can't find any clue in the software menus or online help.

    You can do such ordering with JavaScript. There is a recent post with a JavaScript for dealing with another aspect of page order that might provide what you want. You will have to search the forum for the post that was about 2 or 3 weeks ago as I recall.

  • Can't print even or odd numbered pages

    No matter I choose "even numbered page" or "odd numbered page" in the printer setting,
    it just print out all pages without differences.
    I tried two different printer, hp Laserjet 1300 & Epson stylus C68, and got the same result.
    However, printing even/odd numbered pages works fine in Tiger.
    Does anybody have the same problem?

    sonic64 wrote:
    My friend told me that his Lexmark printer works fine in printing even/odd numbered pages on Leopard.
    However, his printer is directly connected to Airport Express.
    It seems that Gutenprint drivers may not be fully compatible with Leopard.
    That anecdotal experience is good, but it does not further trying to find an answer for your situation. I have had no problems with printing odd or even pages using the Gutenprint drivers with my HP DeskJet 870. That is why I asked if you could connect one of the printers directly to your Mac running Leopard and see if the Gutenprint drivers behave correctly. The goal is to find out whether it is the Gutenprint drivers, something about printing to a shared Windows printer, or something else that is causing this behavior.
    You might also want to try the hpijs drivers for the LaserJet 1300 to see if they are able to print odd or even pages. That also would be of help in determining where the problem is. http://www.linux-foundation.org/en/OpenPrinting/MacOSX/hpijs
    Matt

  • Merge even and odd pages

    My printer won't do duplex scan, and I need to scan a large amount of 2-sided text. So I'm going to create one document of the odd-numbered pages, and another of the even-numbered pages. I know I can manually combine them into the right order, but I'm hoping there is some automatic way to merge the documents - one of odd-numbered pages, and one of even-numbered pages - into one document in which the pages are in the correct numerical order.
    Is there?

    Hey Seth and others:
    Thanks for the positive feedback. I found myself needing to do some collating and reversing again, and discovered that the script didn't show up in Acrobat 9. So I updated the script, and moved the menu item into the "Document" menu.
    Unfortunately I can't figure out how to attach the updated script in the new form editor, so I'll inline it. Copy the following script into a file and install it into your Javascripts folder, as before.
    // Complements: Planet PDF (http://www.planetpdf.com/)
    // Modified by Jeff Baitis for Acrobat 9 compatibility
    // Improved Collate function with status bar.
    // Add a menu item to reverse all pages in the active document
    app.addMenuItem({ cName: "Reverse", cParent: "Document", cExec: "trustedReversePages();", cEnable: "event.rc = (event.target != null);", nPos: 0 });
    app.addMenuItem({ cName: "Collate", cParent: "Document", cExec: "trustedCollatePages();", cEnable: "event.rc = (event.target != null);", nPos: 0 });
    trustedReversePages = app.trustedFunction(function()
      app.beginPriv(); // Explicitly raise privileges
      var t = app.thermometer;
      t.duration = this.numPages;
      t.begin();
      for (i = this.numPages - 1; i >= 0; i--)
        t.value = (i-this.numPages)*-1;
        this.movePage(i);
        t.text = 'Moving page ' + (i + 1);
      t.end();
      app.endPriv();
    // Collating pages
      Title: Collate Document
      Purpose: User is prompted to select document to insert/collate.
      Author: Sean Stewart, ARTS PDF, www.artspdf.com
    trustedCollatePages = app.trustedFunction(function()
      app.beginPriv(); // Explicitly raise privileges
      // create an array to use as the rect parameter in the browse for field
      var arRect = new Array();
      arRect[0] = 0;
      arRect[1] = 0;
      arRect[2] = 0;
      arRect[3] = 0;
      // create a non-visible form field to use as a browse for field
      var f = this.addField("txtFilename", "text", this.numPages - 1, arRect);
      f.delay = true;
      f.fileSelect = true;
      f.delay = false;
      // user prompted to select file to collate the open document with
      app.alert("Select the PDF file to merge with")
      // open the browse for dialog
      f.browseForFileToSubmit();
      var evenDocPath = f.value;
      var q = this.numPages;
      var t = app.thermometer;
      t.duration = q;
      t.begin();
      // insert pages from selected document into open document
      for (var i = 0; i < q; i++) {
          var j = i*2;
          this.insertPages(j, evenDocPath, i);
          t.value = i;
          t.text = 'Inserting page ' + (i+1);
      t.end();
      // remove unused field
      this.removeField("txtFilename");
      app.endPriv();
    Have fun
    Edited: Found some bugs, fixed the code up a bit

  • Split a column based on even and odd rows

    Table1
          Table2
     Col1
    Odd
    Even
      A
     A
      B
      B
     C
      D
      C
     E
      F
      D
     G
      H
      E
     I
    NULL
      F
      G
      H
      I
    I am using MS SQL v2005
    I want to split a column into two columns : -
    one column must have all the odd rows data while the other column must have even rows data
    in other words I want the data in Table1 to be displayed as data in Table2. 
    Col, Odd and Even are column names

    In SQL 2005 wont approach like what I suggested do only a single scan of the table?
    A major problem with your solution is that you assume that 1) the values are contiguous 2) they are numeric. Try the below:
    CREATE TABLE #t (id INT NOT NULL IDENTITY(1,1), Col1 CHAR(1))
    INSERT INTO #t VALUES ('A'),('B'), ('C'),('D'), ('E'),('F'), ('G'), ('H'), ('I')
    go
    SELECT MAX(CASE WHEN Col1 % 2 > 0 THEN Col1 END),
    MAX(CASE WHEN Col1 % 2 = 0 THEN Col1 END)
    FROM
    SELECT Col1,ROW_NUMBER() OVER (PARTITION BY (Col1 % 2) ORDER BY Col1) AS Rn
    FROM #t
    )t
    GROUP BY Rn
    go
    ; WITH numbering AS (
        SELECT Col1, row_number() OVER (ORDER BY Col1) AS rowno
        FROM   #t
    ), leading AS (
       SELECT Col1 AS odd, LEAD(Col1) OVER(ORDER BY rowno) AS even, rowno
       FROM   numbering
    SELECT odd, even
    FROM   leading
    WHERE  rowno % 2 = 1
    go
    DROP TABLE #t
    Erland Sommarskog, SQL Server MVP, [email protected]

  • CSS Even and Odd VLANS

    On the Catalyst 5000 architecture, all Even VLANs are running on one BUS on the backplane and all the odd VLANs are running on the other BUS on the backplane. Is CSS work in the same way? Hence, is it going to be a problem if I have all Even VLANs or all Odd VLANs?
    Thanks,
    /david

    David,
    The CSS does not work in this manner so your vlans can be odd or even and have not effect on the css. The only thing to keep in mind is that ever 4 ports, 1-4, 5-8, 9-12, etc.. are on separate EPIFs. So when doing network planning, you may want to consider separating connections.
    For example, if you are only using a few ports on a CS150, it would be beneficial to use ports 1,5 and 9 as they are all on different EPIFs.
    Regards
    Pete Knoops
    Cisco Systems

  • Selecting even or odd numbered files

    I've got hundreds of files with the following naming scheme: "IMG_0001, IMG_0002," etc.
    I need to select every other file ONLY... or just odd or even numbered files. Is there any way to achieve this on my Mac?
    I've looked around a great deal and can't find a solution to this.

    Whitecity,
    I've been making time-lapses and often have around 2000 high resolution DNG files. I recently made a mistake, where every other photograph had a slightly different exposure and needed to be moved to a separate folder. Manually selecting every other photograph was ridiculously tedious. I figured someone must have created some shareware for this, but it appears that no one has. Luckily, Martin Pace has come up with a creative solution that works great! See above.

Maybe you are looking for