-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray667.java
More file actions
25 lines (24 loc) · 761 Bytes
/
Copy pathArray667.java
File metadata and controls
25 lines (24 loc) · 761 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
/*
Given an array of ints, return the number of times
that two 6's are next to each other in the array.
Also count instances where the second "6" is actually a 7.
*/
package codingbat;
import java.util.Scanner;
public class Array667 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[7];
int flag = 0;
System.out.println("Enter 7 numbers: ");
for (int i = 0; i < 7; i++) {
arr[i] = sc.nextInt();
}
for (int i = 0; i < 6; i++) {
if(arr[i] == 6 && (arr[i+1] == 6 || arr[i+1] == 7)){
flag++;
}
}
System.out.println("The occurence is "+flag+" times.");
}
}