Sunday, July 26, 2015

Smallest Number in Java

In this simple program that I wrote it will allows the user to give a series of numbers and then it will check and display the smallest number from the given number by the user using Java as our programming language.

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

/*
smallest_number_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. 7:
  
Write a program that will ask the user to give five numbers and then
it will search for the smallest number in the given list from the user.
user.
*/
              

import java.util.Scanner;

class smallest_number_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
                   
  do { 
      int [] values; 
      values  = new int[5];  
      int x=0;
      int smallest = Integer.MAX_VALUE;
      System.out.print("SMALLEST NUMBER PROGRAM");
      System.out.println();
      for (int a=0; a<5; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         for(int a =0;a<5;a++) {
           if(smallest > values[a]) 
           {
            smallest = values[a];
            }
        }  
     System.out.println("The smallest number is " + smallest +".");
      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