1. Write a program that asks the user to enter five integers and then adds and outputs the sum of odd integers, and adds and outputs the sum of even integers. For example, if the user enters the integers 7, 4, 2, 1, and 3 then the program should output the following message:

Enter five integers: 7 4 2 1 3
The sum of the odd integers you entered is: 11
The sum of the even integers you entered is: 6

    import java.util.Scanner;

    public class OddEve
    {
        public static void main( String[] arg)
        {
            Scanner in = new Scanner(System.in);
            System.out.print("Enter Numbers: ");
            String numbers = in.nextLine();

            int sumofodd = 0 ;
            int sumofeven = 0;

            for (String retval : numbers.split(" "))
            {

                int number = Integer.parseInt( retval );

                if( (number % 2) == 1 )
                {
                    sumofodd += number;
                }
                else if( (number % 2) == 0 )
                {
                    sumofeven += number;
                }
            }
            System.out.println("The sum of the odd integers you entered is: "+ sumofodd);
            System.out.println("The sum of the even integers you entered is: "+ sumofeven);
        }   
    }
Comments
way to help someone cheat
This is their homework assignment, not yours. It's best to help them solve it.

While someone was so kind as to post a complete implementation of your homework problem, it would probably be wise for you to implement your own solution -- using only the features of Java that you have studied in class. Otherwise, your instructor will know that someone gave you the answer.

I will agree with JeffGrigg here. At least show what you have been able to do. Where you are having problems.
Am sure with the solution already posted you should be able to adapt to your own code.

abeer_araji: that is not a Java problem, that is an assignment.
the problem I see is that you didn't even try to write the code yourself.
now, looks like hakeemtunde wants to help you cheat your way through school. just a few remarks about it:

  1. you won't learn squat by just copy-pasting code
  2. teachers and instructors these days have heard of that new "google" thingy, and yes, they do look for proof of plagiarism. don't know what kind of school you are in, but there isn't a school in the world that won't give you a 0 for handing in the solution above, there are also tons of schools who will expell you. so better think twice about handing it in.

but, of course I leave the best for last: I spotted (at least) 2 things in which the above "solution" is not meeting the requirements? did you spot them, too?

happy hunting.

Which everway you thought of it... abeer araji might understood that what i did was answer to his question but then he start questioning himself how did the code come to be. He proberly have the pieace but couldn't figure out how to put them together.

but, of course I leave the best for last: I spotted (at least) 2 things in which the above "solution" is not meeting the requirements? did you spot them, too?

am glad for the above statement... probarbly the code could be a good start if realy he wants to learn.

Enjoy

hakeemtunde: he probably doesn't have the pieces to puzzle together, if he had, he would have posted them here.
the point is to help him better understand what he is doing, or should be doing, not provide him with custom made code. all he 'll learn from that is copy pasting, and since he managed to copy paste his assignment here, I'm pretty sure he has that part of IT covered.

This article has been dead for over six months. Start a new discussion instead.