vendredi 26 février 2016

Trying to get the odd Numbers to Print

I have a Program that asks a user to input positive numbers. Then the program prints out the user input then takes the evens out and displays the evens.Now when i try to display the odds it prints out both even and odd numbers.. i have the if statement if(oddNum%2 ! =0)// meaning if not even execute the following.. cant seem to figure out my mistakes.

            System.out.println("\n");
            System.out.println("Here is the new even array: ");
            for(j=0; j<i;j++)
            {
                if (oddNum[j]%2 == 0)//if odd num equals zero separate the evens
                {
                    System.out.println("evenNum1:"+evenNum);
                evenNum[evenIndex]=oddNum[j];//sorts the even numbers to the next array
                evenIndex++;

                }
            }

            if(evenIndex !=0)
            {
            for(j=0;j<evenIndex;j++)
            {
                if(evenNum[j]>0)
                {
                    System.out.println(evenNum[j]);
                }
            }

            }
            System.out.println("\n");
            System.out.println("Here is the new odd array: ");
            for(b=0;b<i;b++)
            {
                if(oddNum[b]%2!=0 )//if odd
                {

                    oddNum[oddIndex]=evenNum[b];//sorts the input numbers to the next array
                    oddIndex++;



                }
            }
            if(oddIndex!=0)
            {
                for(b=0;b<oddIndex;b++)
                {
                    if(oddNum[b]>0)
                    {
                        System.out.println(oddNum[b]);
                    }
                }
            }
     }

 }

Aucun commentaire:

Enregistrer un commentaire