Q:

Write a Java program to get the larger value between first and last element of an array (length 3) of integers

0

Write a Java program to get the larger value between first and last element of an array (length 3) of integers

Sample Output:

Original Array: [20, 30, 40]                                           
Larger value between first and last element: 40 

All Answers

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

import java.util.Arrays; 
 public class Exercise80 {
 public static void main(String[] args)
 {
    int[] array_nums = {20, 30, 40};
	System.out.println("Original Array: "+Arrays.toString(array_nums)); 
	int max_val = array_nums[0];
	if(array_nums[2] >= max_val)
		max_val = array_nums[2];
	System.out.println("Larger value between first and last element: "+max_val); 	 
 }
}

Sample Output:

Original Array: [20, 30, 40]                                           
Larger value between first and last element: 40

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now