java program to find smallest element in array

package arraysmall;
import java.io.*;
import java.util.*;

public class Arraysmall {


    public static void main(String[] args) {
 
        int num,i,min=0;
                System.out.println("Enter the size of array");
                Scanner sc=new Scanner(System.in);
                num=sc.nextInt();
                System.out.println("Enter elements in the array one by one");
                int array[]=new int [50];
             
                for(i=0;i<num;i++)
                {
                    array[i]=sc.nextInt();
                }
                System.out.println(" The entered element in the array is");
                for(i=0;i<num;i++)
                {
                    System.out.println(array[i]);
                         
                }
                System.out.println("The smallest element in the array is");
                min=array[0];
                for(i=0;i<num;i++)
             
                {
                 
                 
                    if(min>array[i])
                        min=array[i];
                     
                     
                 
                       
                }   System.out.println(min);
                 
 
    }
 
 
}
output-
Enter the size of array
5
Enter elements in the array one by one
12
89
32
75
19
 The entered element in the array is
12
89
32
75
19
The smallest element in the array is
12

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation