填空题考察的一般是代码阅读能力和逻辑思维,直接上代码:
package pastExamPaper;
/*
取数位(代码填空题)
*/
public class Demo88 {
static int len(int x){
if (x < 10) return 1;
return len(x/10)+1;
}
/**
* 取x的第k位
* @param x
* @param k
* @return
*/
static int f(int x, int k){
if (len(x) - k == 0) return x%10;
return f(x/10,k);//填空位置
}
public static void main(String[] args) {
int x = 23513;
System.out.println(len(x));
System.out.println(f(x,4));
}
}