Q:

Write a Java program to test if 10 appears as either the first or last element of an array of integers

0

Write a Java program to test if 10 appears as either the first or last element of an array of integers. The length of the array must be greater than or equal to 2


Sample Output:
Test Data: array = 10, -20, 0, 30, 40, 60, 10

true

All Answers

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

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

Sample Output:

true

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