Showing posts with label odd and even numbers in java. Show all posts
Showing posts with label odd and even numbers in java. Show all posts

Sunday, February 19, 2017

Summation of Odd and Even Numbers in Java

Here there I am very happy that more and move visitors visiting my site even though it is not earning but I am happy that more people benefited from my works and my friends works also who contribute their work in my website.

I this article I would like to share with you a sample program that will ask the user to give five numbers and then it will sum up all the odd and even numbers that the user given. I am using one dimensional array and methods in Java I hope you like my work. Thank you so much.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

sum_odd_even.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sum_odd_eve;


import java.util.Scanner;

/**
 *
 * @authors Jake R. Pomperada and Jacob Samuel F. Pomperada
 * Date : February 19, 2017  Sunday
 * Language : Java
 * IDE     : NetBeans
 */
public class sum_odd_even {

    /**
     * @param args the command line arguments
     */
    
    void display()
    {
         int val_items=0, total_sum_even = 0, total_sum_odd = 0;

        Scanner s = new Scanner(System.in);

        val_items =  5;
        int[] array_value = new int[val_items];

        System.out.println();
        System.out.println("=== SUMMATION OF ODD AND EVEN NUMBERS IN JAVA === ");
        System.out.println();
        for(int b = 0; b < val_items; b++)

        {
           System.out.print("Enter value in item no. " + (b+1) + " : ");
            array_value[b] = s.nextInt();
       }

        for(int b = 0; b < val_items; b++)

        {
            if(array_value[b] % 2 == 0)

            {

                total_sum_even +=  array_value[b];

            }

            else

            {

                total_sum_odd += array_value[b];
            }

        }
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The Total Sum  of Even Numbers is "
                  + total_sum_even + ".");

        System.out.println("The Total Sum  of Odd Numbers is "
                  + total_sum_odd + ".");
        System.out.println();
        System.out.println("===== END OF PROGRAM ======");
        System.out.println();
    }
    
    public static void main(String[] args)
      {
        // TODO code application logic here
      sum_odd_even demo  = new sum_odd_even();
      demo.display();
            
    }
    
}