Sunday, October 4, 2015

Odd and Even Numbers in Java using Two Dimensional Array

A simple program that I wrote in Java programming language that will list down the odd and even numbers from the values given by the user using two dimensional array as our data structure. I hope you will find my work useful in your programming projects and assignments.

If you  have some questions please send me an email  at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

/*
odd_even_numbers_array.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 23, 2015
Tools: NetBeans 8.0.2, Java SE 8.0

Problem No. 2:
  
Write a program that will ask the user to give ten numbers and then
the program will enumerate the odd and even numbers based on the 
given numbers by the user. Kindly use two dimensional array as
your data structure in this problem.
*/
              

import java.util.Scanner;

class odd_even_numbers_two_dimesional {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [][] values; 
      values  = new int[10][1];  
      int x=0;
      System.out.print("ODD AND EVEN NUMBERS PROGRAMS");
      System.out.println();
      for (int a=0; a<10; a++){
          for (int b=0; b<1; b++) 
         {
         System.out.print("Enter value in item no. " + (a+1) + " : ");
         values[a][b] = input.nextInt();
        }
      }  
         System.out.println(); 
         System.out.print("LIST OF EVEN NUMBERS");
         System.out.println();
      for (int a=0; a<10; a++)
      {
          for (int b=0; b<1; b++) 
         {
           if(values[a][b]%2 == 0) {
                System.out.print(" " + values[a][b]+ " ");
                }
         }       
      }        
      System.out.println(); 
      System.out.print("LIST OF ODD NUMBERS ");
      System.out.println(); 
      for (int a=0; a<10; a++)
      {
          for (int b=0; b<1; b++) 
         {
          if(values[a][b]%2 != 0) {
              System.out.print(" " + values[a][b]+ " ");
                }
         }
      }     
     System.out.println("\n\n"); 
     System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println("\n\n");
  }
} // End of Code
    




No comments:

Post a Comment