-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeams.java
More file actions
42 lines (35 loc) · 1.16 KB
/
Beams.java
File metadata and controls
42 lines (35 loc) · 1.16 KB
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
/* *****************************************************************************
* Name: Ada Lovelace
* Coursera User ID: 123456
* Last modified: October 16, 1842
**************************************************************************** */
public class Beams {
public static void main(String[] args) {
String[] str = new String[] { "011001", "000000", "010100", "001000" };
System.out.println(numberOfBeams(str));
}
private static int numberOfBeams(String[] bank) {
int count1 = 0, count = 0, beams = 0;
for (int i = 0; i < bank.length; i++) {
for (int j = 0; j < bank[i].length(); j++) {
if (bank[i].charAt(j) == '1') {
count++;
}
}
if (count > 0) {
if (count1 == 0) {
count1 = count;
}
else {
beams += (count1 * count);
count1 = count;
}
}
count = 0;
}
return beams;
}
/*
["011001","000000","010100","001000"]
["000","111","000"]*/
}