JAVA中三维倒三角金字塔怎么编,求解
前面不写了,直接写内容:int[][][]s=newint[30][][];for(inti=0;i<a.length;i++){for(intj=0;j<=i;j++)...
前面不写了,直接写内容:
int[][][] s=new int[30][][];
for(int i=0;i<a.length;i++){
for(int j=0;j<=i;j++){
s[i]=new int[j+1][];
for(int k=0;k<=j;k++){
s[i][j]=new int[k+1];
}
}
}
编一个三维30层倒三角金字塔数组这样写对吗?求详细解,万分感谢!!! 展开
int[][][] s=new int[30][][];
for(int i=0;i<a.length;i++){
for(int j=0;j<=i;j++){
s[i]=new int[j+1][];
for(int k=0;k<=j;k++){
s[i][j]=new int[k+1];
}
}
}
编一个三维30层倒三角金字塔数组这样写对吗?求详细解,万分感谢!!! 展开
1个回答
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Sum {
public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("请输入一个正整数按回车键:");
String numStr = bf.readLine();
int num = Integer.parseInt(numStr);
System.out.println(num);
for (int i = 0; i <= num; i++) {
for (int m = 1; m <= Math.abs(i); m++) {
System.out.print(" ");
}
for (int n = 1; n <= (num * 2 + 1) - 2 * Math.abs(i); n++) {
System.out.print("*");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
System.out.println("请输入正整数!");
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Sum {
public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("请输入一个正整数按回车键:");
String numStr = bf.readLine();
int num = Integer.parseInt(numStr);
System.out.println(num);
for (int i = 0; i <= num; i++) {
for (int m = 1; m <= Math.abs(i); m++) {
System.out.print(" ");
}
for (int n = 1; n <= (num * 2 + 1) - 2 * Math.abs(i); n++) {
System.out.print("*");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
System.out.println("请输入正整数!");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询