Monday, March 9, 2015

Highest and Lowest Number Finder in Java

In this simple article I would like to share with you a sample program in Java that I wrote that will find the highest and lowest number given by our user. I'm using one dimensional array to accept and store integer numerical values and our program will check and compare which of the list of values given by the user in highest and lowest. Our program also ask the user if the they want to continue using the program or not by asking the user do you want to continue or not.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Program Listing

import  java.util.Scanner;

public class high_low{

        public static void main(String[] args) {

                Scanner input = new Scanner(System.in);
                char a;
do
 {


 System.out.print("\n");
  System.out.println("==============================================");
  System.out.println("|| << HIGHEST AND LOWEST NUMBER FINDER  >>  ||");
    System.out.println("==============================================");
          System.out.print("\n");
  System.out.print("How Many Items To Be Process :=> ? ");

                int num = input.nextInt();

                int numbers[] = new int[num];
                  int largest_number = numbers[0];
 int smallest_number = numbers[0]+1;

                for(int i=0; i< numbers.length; i++)
                {

                   int b=i+1 ;

                   System.out.print("Enter Value in Item No. "+b + " : ");


                numbers[i] = input.nextInt();

                  if(numbers[i] > largest_number)
                             largest_number = numbers[i];
                     else if (numbers[i] < smallest_number)
                              smallest_number = numbers[i];

                }

                System.out.println("\n\n");
                System.out.println("THE LARGEST NUMBER IS   :=> " + largest_number);
                System.out.println("THE SMALLEST NUMBER IS  :=> " + smallest_number);
               System.out.println("\n\n");
               System.out.print("Do you Want To Continue (Y/N) :=> ");
            a=input.next().charAt(0);

    } while(a=='Y'|| a=='y');
           System.out.println("\n");
           System.out.println("\t ===== END OF PROGRAM ======");
                  System.out.println("\n");

}

}



No comments:

Post a Comment