Largest And Smallest Number Program Using Java With I/O Stream

Introduction

 
In this blog, I will explain about the largest and smallest number in the given array program, using Java. It is very simple in Java Programming. The output will be displayed in the Run module.
 
Software Requirement
 
JDK1.3.
 
Simple Program
  1. import java.io.*;  
  2. class large {  
  3.  public static void main(String arg[]) throws IOException {  
  4.   DataInputStream dr = new DataInputStream(System.in);  
  5.   System.out.println("Enter the size of Array : ");  
  6.   int no = Integer.parseInt(dr.readLine());  
  7.   int a[] = new int[no];  
  8.   System.out.println("Enter the Elements of Array...");  
  9.   for (int i = 0; i < no; i++) {  
  10.    a[i] = Integer.parseInt(dr.readLine());  
  11.   }  
  12.   int small = a[0];  
  13.   int large = a[0];  
  14.   for (int i = 0; i < no; i++) {  
  15.    if (a[i] > large)  
  16.     large = a[i];  
  17.    else if (a[i] < small)  
  18.     small = a[i];  
  19.   }  
  20.   System.out.println("The Smallest Number of the given array is : " + small);  
  21.   System.out.println("The Largest Number of the given array is : " + large);  
  22.  }  
  23. }   
Explanation
 
In this blog, I will explain about the largest and smallest number in the given array program using Java. The output will be displayed in the Run module.

Output
 
a