mac版eclipse用JAVA写的正方形运行后根本就不是,为什么啊?和系统有关系吗
publicclassyanghuisanjiao{publicstaticvoidmain(String[]args){inttriangle[][]=newint[8...
public class yanghuisanjiao {
public static void main(String[] args) {
int triangle[][]=new int[8][];
for (int i =0;i<triangle.length;i++){
triangle[i]=new int[i+1];
for (int j=0;j<=triangle[i].length-1;j++){
if(i==0||j==0||j==triangle[i].length-1){
triangle[i][j]=1;
}else {
triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];
}
System.out.println(triangle[i][j]+"\t");
}
}
System.out.println();
}
}
public class yanghuisanjiao {
public static void main(String[] args) {
int triangle[][]=new int[8][];
for (int i =0;i<triangle.length;i++){
triangle[i]=new int[i+1];
for (int j=0;j<=triangle[i].length-1;j++){
if(i==0||j==0||j==triangle[i].length-1){
triangle[i][j]=1;
}else {
triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];
}
System.out.println(triangle[i][j]+"\t");
}
}
System.out.println();
}
}
这是另一个杨辉三角的,照着书写的,出来的也不是个三角形! 展开
public static void main(String[] args) {
int triangle[][]=new int[8][];
for (int i =0;i<triangle.length;i++){
triangle[i]=new int[i+1];
for (int j=0;j<=triangle[i].length-1;j++){
if(i==0||j==0||j==triangle[i].length-1){
triangle[i][j]=1;
}else {
triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];
}
System.out.println(triangle[i][j]+"\t");
}
}
System.out.println();
}
}
public class yanghuisanjiao {
public static void main(String[] args) {
int triangle[][]=new int[8][];
for (int i =0;i<triangle.length;i++){
triangle[i]=new int[i+1];
for (int j=0;j<=triangle[i].length-1;j++){
if(i==0||j==0||j==triangle[i].length-1){
triangle[i][j]=1;
}else {
triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];
}
System.out.println(triangle[i][j]+"\t");
}
}
System.out.println();
}
}
这是另一个杨辉三角的,照着书写的,出来的也不是个三角形! 展开
2个回答
展开全部
应该不是。
把代码贴出来看看。
=========================================
public static void main(final String[] args) {
final int triangle[][] = new int[8][];
for (int i = 0; i < triangle.length; i++) {
triangle[i] = new int[i + 1];
for (int j = 0; j <= triangle[i].length - 1; j++) {
if (i == 0 || j == 0 || j == triangle[i].length - 1)
triangle[i][j] = 1;
else
triangle[i][j] = triangle[i - 1][j] + triangle[i - 1][j - 1];
System.out.print(triangle[i][j] + "\t");
}
System.out.println();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询