解题思路:
注意事项:
参考代码:import java.util.Scanner;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = (int) Math.pow(a, 3);
int c = a * a;
if (a % 2 != 0) {
System.out.print(a + "*" + a + "*" + a + "=" + b + "=");
int d[] = new int[(a - 1) / 2];
for (int i = 0; i < (a - 1) / 2; i++) {
d[i] = c - 2;
c = c - 2;
}
for (int i = (a - 1) / 2 - 1; i >= 0; i--) {
System.out.print(d[i] + "+");
}
int t = a * a;
System.out.print(t);
for (int i = 1; i <= (a - 1) / 2; i++) {
t = t + 2;
System.out.print("+" + t);
}
}
if (a % 2 == 0) {
System.out.print(a + "*" + a + "*" + a + "=" + b + "=");
int d[] = new int[a / 2];
for (int i = 0; i < a / 2; i++) {
d[i] = c - 1;
c = c - 2;
}
for (int i = a / 2 - 1; i > 0; i--) {
System.out.print(d[i] + "+");
}
for(int i=0;i<1;i++) {
System.out.print(d[0]);
}
int t = a * a + 1;
for (int i = 1; i <= a / 2; i++) {
System.out.print("+" + t);
t = t + 2;
}
}
}
}
0.0分
0 人评分
母牛的故事 (C语言代码)浏览:1389 |
Hello, world! (C语言代码)浏览:1311 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:778 |
最小公倍数 (C语言代码)浏览:894 |
【亲和数】 (C语言代码)浏览:903 |
程序员的表白 (C语言代码)浏览:704 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:1050 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:616 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:624 |
有关字符,字符串的输入输出函数说明浏览:498 |