題目:
代碼:
import java.util.Scanner;
public class CountOff {
public static int[] countoff(int n){
int[] count = new int[5];
boolean include7=false;
String n2s;
char[] s2c;
for (int k = 0; k < count.length; k++) {
count[k]=0;
}
for(int i=1;i<=n;i++){
include7 = false;
n2s = String.valueOf(i);
s2c = n2s.toCharArray();
for (int t = 0; t < s2c.length; t++) {
if (s2c[t] == '7') {
include7 = true;
break;
}
}
if (i%7 == 0 || include7) {
n+=1;
int j=i%4;
if (j == 0) {
count[4]++;
} else {
count[j]++;
}
}
}
return count;
}
public static void main(String[] args) {
int n;
int[] a = new int[5];
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
a = countoff(n);
for(int i=1;i<=4;i++){
System.out.println(a[i]);
}
}
}
主類名稱改為Main
int 轉(zhuǎn) string String.valueOf()
string 轉(zhuǎn) char[] str.toCharArray()