A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Java program to get the difference between the largest and smallest values in an array of integers
Q:

Write a Java program to get the difference between the largest and smallest values in an array of integers

0

Write a Java program to get the difference between the largest and smallest values in an array of integers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Arrays; 
 public class Javaexcercise {
 public static void main(String[] args)
 {
    int[] myarray = {10,20,30,40,50,60,70,80,90};
    System.out.println("Original Array: "+Arrays.toString(myarray)); 
    int maxval = myarray[0];
    int min = myarray[0];
    for(int i = 1; i < myarray.length; i++)
    {
        if(myarray[i] > maxval)
            maxval = myarray[i];
        else if(myarray[i] < min)
            min = myarray[i];
    }
    System.out.println("Difference between the largest and smallest araay element is: "+(maxval - min));    
 }
}

Result:

Original Array: [10, 20, 30, 40, 50, 60, 70, 80, 90]

Difference between the largest and smallest araay element is: 80

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now