-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray123.java
More file actions
36 lines (34 loc) · 1014 Bytes
/
Copy patharray123.java
File metadata and controls
36 lines (34 loc) · 1014 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
/*
Given an array of ints, return true if the sequence of numbers 1, 2, 3 appears in the array somewhere.
*/
package codingbat;
import java.util.*;
public class array123 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[6];
boolean flag = false;
System.out.println("Enter 6 numbers:");
for(int i = 0; i < arr.length; i++){
arr[i] = sc.nextInt();
}
for(int i = 0; i < arr.length - 2; i++){
if(arr[i] == 1){
if(arr[i+1] == 2){
if(arr[i+2] == 3){
flag = true;
}
}
}
else{
flag = false;
}
}
if(flag == true){
System.out.println("1, 2, 3 are in sequence!");
}
else{
System.out.println("1, 2, 3 are not in sequence!");
}
}
}