MCPcopy Create free account
hub / github.com/MohamedMetwalli5/HackerRank-Solutions / FindDigits

Class FindDigits

ProblemSolving (General)/FindDigits.java:9–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.util.regex.*;
8
9public class FindDigits {
10
11 // Complete the findDigits function below.
12 static int findDigits(int n) {
13 int temp = n, digit = 0 , result = 0;
14 while(temp > 0){
15 digit = temp%10;
16 temp /= 10;
17 if(digit != 0 && n % digit == 0){
18 result++;
19 }
20 }
21
22 return result;
23
24 }
25
26 private static final Scanner scanner = new Scanner(System.in);
27
28 public static void main(String[] args) throws IOException {
29 BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
30
31 int t = scanner.nextInt();
32 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
33
34 for (int tItr = 0; tItr < t; tItr++) {
35 int n = scanner.nextInt();
36 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
37
38 int result = findDigits(n);
39
40 bufferedWriter.write(String.valueOf(result));
41 bufferedWriter.newLine();
42 }
43
44 bufferedWriter.close();
45
46 scanner.close();
47 }
48}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected