Results 1 to 3 of 3
  1. #1
    judgety is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default Array Odds and Evens

    Create an array of 10 integers. Write a program print all the odd numbers then, on a new line, print out the number of even numbers.
    Steps

    I'm a newb, and getting stuck on how to properly print out the odds and count the evens. So far I'm getting it to print the odds in a list, but then it's just printing everything else after?

    public class ArrayProblem{
    public static void main(String[] args){

    int [] newArray = {9,45,11,2,4,6,8,10,12,14};

    System.out.println("The odd numbers are :");

    for(int i=0;i<newArray.length;i++){

    if(newArray[i]/2 != 0){
    System.out.println(newArray[i]);
    }
    else{

    }
    }
    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Array Odds and Evens

    Clearly you need to add some code to the else part. The if handles the odd numbers. So what should the else do?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Array Odds and Evens

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 15
    Last Post: 05-14-2012, 12:42 PM
  2. Evens odds & likes 7
    By Martyn in forum New To Java
    Replies: 6
    Last Post: 11-15-2011, 10:36 AM
  3. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  4. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  5. Replies: 2
    Last Post: 09-06-2010, 01:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •