目录
一、三角形面积(3/3分)
解题思路:
数学题,比较简单~
代码如下:
public class 三角面积 {
public static void main(String[] args) {
System.out.println(7 * 4 / 2 * 2);
}
}
二、立方变自身(5/5分)
解题思路:
得到每一个位上面的数并累加,如果与这个数本身相等则++。
代码如下:
public class 立方变自身 {
public static void main(String[] args) {
int cnt = 0;
for (int i = 1; i < 10000; i++) {
if(check(i)) {
cnt++;
}
}
System.out.println(cnt);
}
public static boolean check(long n) {
long num = n * n * n;
long sum = 0;
while(num > 0) {
long ge = num % 10;
sum += ge;
num /= 10;
}
if(sum == n) {
return true;
}
else {
return false;
}
}
}
三、三羊献瑞(9/9分)
解题思路1:
每个汉字代表一个数字,一共有八个不同的汉字,所以八层循环表示每一个汉字可能的值,再判断这些汉字带入算式是否符合条件,同时三个数的开头不能是0。
代码如下:
public class 三羊献瑞 {
public static void main(String[] args) {
for (int a = 0; a < 10; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 10; c++) {
for (int d = 0; d < 10; d++) {
for (int e = 0; e < 10; e++) {
for (int f = 0; f < 10; f++) {
for (int g = 0; g < 10; g++) {
for (int h = 0; h < 10; h++) {
if(a != b && a != c && a != d && a != e &&
a != f && a != g && a != h &&
b != c && b != d && b != e && b != f &&