-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayUsingLoops.java
More file actions
50 lines (36 loc) · 1021 Bytes
/
Copy pathArrayUsingLoops.java
File metadata and controls
50 lines (36 loc) · 1021 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Array using loops program
* 1)Given an array of ints, return true if..1,2,3,..appears in the array somewhere
* Example:
* input:[1,1,2,3,1]--output:true
* input:[1,1,2,4,1]--output:false;
* input:[1,1,2,1,2,3]--output:true;
* */
import java.util.Scanner;
public class ArrayUsingLoops {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.print("Enter given array length: ");
int length = scn.nextInt();
int[] arr = new int[length];
System.out.println("Enter array elements:");
for (int i = 0; i < length; i++) {
arr[i] = scn.nextInt();
}
System.out.println("Array elements is: ");
boolean value = ArrayUsingLoops.arraycheck(arr);
if (value) {
System.out.println("True");
} else {
System.out.println("False");
}
}
public static boolean arraycheck(int[] arr) {
for (int j = 0; j < arr.length; j++) {
if (arr[j] == 1 && arr[j + 1] == 2 && arr[j + 2] == 3) {
return true;
}
}
return false;
scn.close();
}
}