-
Notifications
You must be signed in to change notification settings - Fork 1
/
Question6.java
35 lines (27 loc) · 839 Bytes
/
Question6.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class Question6 {
public static void main(String[] args) {
/*
* 6. Given an array of int, return true if the array’s length is bigger than or
* equal to 3, and the first and last element are the same.
*
* sameFirstLast({1, 2, 3}) — false
* sameFirstLast({1, 2, 3, 1}) — true
* sameFirstLast({1, 2, 1}) — true
*/
int[] arr1 = {1, 2, 3};
int[] arr2 = {1, 2, 3, 1};
int[] arr3 = {1, 2, 1};
if(arr1.length>=3 && arr1[0] == arr1[arr1.length -1]) {
System.out.println("true");
}else
System.out.println("false");
if(arr2.length>=3 && arr2[0] == arr2[arr2.length -1]) {
System.out.println("true");
}else
System.out.println("false");
if(arr3.length>=3 && arr3[0] == arr3[arr3.length -1]) {
System.out.println("true");
}else
System.out.println("false");
}
}