/*
This is one way to solve. Below approach converts the digits into a String, then iterates thru the String and checks if each digit in the String "0675" (or not) and updates the buzzer var appropriately. Note, using array of test cases instead of user input. Replaced a few lines with placeholders in "<>".
*/
public class Buzzers {
public static void main(String[] args) {
// Used array of test cases instead of user input. Replace with use of Scanner class for user input
int testCases[] = { 24789, 2307, 6750, 8888, 9999999, 7, 123489 };
for (int testCaseCount = 0; testCaseCount < testCases.length; testCaseCount++) {
int digits = testCases[testCaseCount];
int buzzers = 0;
// Convert to a String
String digitsAsString = String.valueOf(digits);
// Iterate thru the String of digits
<CREATE FOR LOOP TO ITERATE THRU DIGITS> {
// get the next char from the String of digits
char nextChar = <GET NEXT CHAR FROM STRING OF DIGITS>
// check if we should add 1 or 2
if (<CHECK IF NEXT CHAR NOT IN THE STRING "0675">) {
// not found, so add 2
buzzers += 2;
} else {
buzzers += 1;
}
}
System.out.println(String.format("For Test Case %s(%d), number of buzzers: %d", testCaseCount + 1,
testCases[testCaseCount], buzzers));
}
}
}