Java Programming : Write a JAVA Program to find the minimum of an array of numbers

Posted on:
tags: ,


Assignment no. : 1
Objective:
The objective of this assignment is to learn how to write Simple JAVA Program.

import java.util.*;
public class a11 {
     public static void main(String args[])throws Exception
         {
                                Scanner br = new Scanner (System.in);
                                System.out.println("Enter the no. of elements");
                                int n = br.nextInt();
                                int arr[]=new int[n];
                System.out.println("Enter the elements");
                for(int i=0;i<n;i++)
                arr[i] = br.nextInt();
                                System.out.println("Array created.......\n");
                int min=arr[0];
                int d=0;
                for(int j=0;j<n;j++)
                 {

                        if(min>arr[j])
                         {

                                min=arr[j];
                                d=j;
                         }
                 }
                                System.out.print("Minimum no. is "+min);
                System.out.print(" for index "+d);

         }

}
OUTPUT:
Enter the elements
66
65
77
44
22
Array created.......

Minimum no. is 22 for index 4




No comments:

Post a Comment

< >