Please Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Please Help

  1. #1
    Join Date
    Apr 2003
    Posts
    6

    Please Help

    1 Write a program that inputs integers from the keyboard (no limit to the entries; end by entering 0), and lists the even numbers and then lists the odd numbers.


    int odd =0;
    int even =0;
    int entry=1;

    //get input
    while (entry !=0)

    {System.out.println("Enteryour integers.");
    System.out.println("Enter 0 to exit the program.");
    entry = MyInput.readInt();



    i know how to get the numbers nut not how sepperated the numbers odd from even

  2. #2
    Join Date
    May 2003
    Posts
    2
    i assume you mean that the program must display the number of odd and the number of even integers entered?
    to check if a number is even or odd you can use the % operator:

    if( ( myNumber % 2 ) == 0 )
    {
    //the number is even so add 1 to your even counter
    }
    else
    {
    //the number is odd so add 1 to your odd counter
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center