03.01 这个貌似要写成递归才会有3星
public class Program {
public static int Puzzle(int number, int power) {
return power<=0 ? 1 : number*Puzzle(number, power-1);
}
}
03.02
public class Program {
public static int Puzzle(int i) {
return i == 0?1:i*Puzzle(i-1);
}
}
public class Program {
public static int Puzzle(int lowerBound, int upperBound) {
return lowerBound>upperBound? 1 :lowerBound*Puzzle(lowerBound+1, upperBound);
}
}
03.04
public class Program {
public static int Puzzle(int n) {
if (n <= 2) {
return 0;
}
return ((n-1)/2)*((n-1)/2+1);
}
}
03.05
public class Program {
public static int Puzzle(int upperBound) {
return (upperBound)*(upperBound+1)*(upperBound+2)/6;
}
}
03.06
public class Program {
public static String Puzzle(String word) {
return word.replaceAll("[a-z]", "_ ").trim();
}
}
03.07 凯撒密码
public class Program {
public static String Puzzle(String s) {
char[] c = s.toCharArray();
for (int i = 0; i < s.length(); i++) {
c[i] = (char)((c[i]-'a'+5)%26 + 'a');
}
return new String(c);
}
}
03.08
public class Program {
public static int Puzzle(int x) {
return (x+"").length();
}
}