Q:

Write a Java program to test if the first and the last element of an array of integers are same

0

Write a Java program to test if the first and the last element of an array of integers are same. The length of the array must be greater than or equal to 2
Test Data: array = 50, -20, 0, 30, 40, 60, 10


Sample Output:

false

All Answers

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

import java.lang.*;
 public class Exercise75 {
 public static void main(String[] args)
 {
    int[] num_array = {50, -20, 0, 30, 40, 60, 10};
    
	System.out.println (num_array.length >= 2 && num_array[0] ==  num_array[num_array.length-1]);
 }
}

Sample Output:

false

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