Define a class to accept values into a double array of size 20 and print the range of the array, range is the difference between the largest and the smallest elements of the array
Solution:
Define a class to accept values into a double array of size 20 and print the range of the array, range is the difference between the largest and the smallest elements of the array.
 


import java.util.*;
class Diff
{
public static void main (String args[])
{
    double a[]=new double[20];
    Scanner sc = new Scanner(System.in);

    for(int i=0; i< 20; i++)
    {
        System.out.println("Enter the "+(i+1)+" element:");
        a[i]=sc.nextDouble();
    }
    double max=a[0], min=a[0];
    for (int i=0; i < a.length; i++)
    {
        if(a[i]>max)
            max=a[i];
            
        if(a[i]< min)
            min=a[i];
        }
    System.out.println("The largest element in the array is :" + max);
    System.out.println("
The smallest element of the array is :" + min);
    System.out.println("
The range of array is : " + (max-min));
}
}
                                                                            


                                            



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com