-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoTriples.java
More file actions
33 lines (32 loc) · 944 Bytes
/
Copy pathnoTriples.java
File metadata and controls
33 lines (32 loc) · 944 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
/*
Given an array of integers, we'll say that a triple is a value
appearing 3 times in a row in the array. Return true if the
array does not contain any triples.
*/
package codingbat;
import java.util.*;
public class noTriples {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[5];
int flag = 0;
System.out.println("Enter 5 numbers:");
for(int i = 0; i < 5; i++){
arr[i] = sc.nextInt();
}
for(int i = 0; i < 3; i++){
int x = arr[i];
if(x == arr[i+1]){
if(x == arr[i+2]){
flag = 1;
}
}
}
if(flag == 1){
System.out.println("It contains triples!");
}
else{
System.out.println("It does not contain triples!");
}
}
}