Showing posts with label positive and negative numbers in java. Show all posts
Showing posts with label positive and negative numbers in java. Show all posts

Thursday, July 23, 2015

Positive and Negative Numbers in Java

This simple program will give you a first hand idea how to use one dimensional array in Java. What the program does is to ask the user to give a series of numbers and then the program will display the positive and negative numbers that is being given by our user.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

/*
positive_negative_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. 4:
  
Write a program that will ask the user to give ten numbers and then
the program will enumerate the positive and negative numbers based 
on the given numbers by the user.
*/
              

import java.util.Scanner;

class positive_negative_numbers_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [] values; 
      values  = new int[10];  
      int x=0;
      System.out.print("POSITIVE AND NEGATIVE NUMBERS PROGRAMS");
      System.out.println();
      for (int a=0; a<10; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         System.out.print("LIST OF POSITIVE NUMBERS");
         System.out.println();
      for (int a=0; a<10; a++)
      {
         if(values[a]>= 0) {
                System.out.print(" " + values[a]+ " ");
                }
       
      }        
      System.out.println(); 
      System.out.print("LIST OF NEGATIVE NUMBERS ");
      System.out.println(); 
      for (int a=0; a<10; a++)
      {
         if(values[a] < 0) {
               System.out.print(" " + values[a]+ " ");
                }
      }     
     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