所以我最近尝试做HackerRank挑战,包括计算一个数字的漏洞并将它们加起来,经过一些研究,我最终将它变成一个char数组并选择三个值来递增并加起来如图所示下面:
public static int countHoles(int num) {
//create integers that count how many a number with no, one or two holes shows up
Integer noHoles = 0;
Integer oneHole = 0;
Integer twoHoles = 0;
Integer sum = 0;
Integer length = 0;
//turn the inputted number into a char array
char [] digits = String.valueOf(num).toCharArray();
System.out.println(digits);
length = digits.length;
//These nested loops incremement the numbers initialized above as the first for-each loop goes through each index value of the …Run Code Online (Sandbox Code Playgroud)