0
我試圖打印這個模式,就像我在給出的代碼片段中顯示的那樣。但不知何故,我不知道我是如何將這個奇怪的輸出與所需的輸出一起出現的。如果你們可以幫忙我會很感激糾錯模式錯誤
/*2 6 12 20 30 42
* 4 6 8 10 12
* 2 2 2 2
* 0 0 0
* 0 0
* 0
*
*/
public class patt {
static int ar[]={2,6,12,20,30,42};
public static void pattern(){
int y=0,x=0;
while(x<ar.length){
int c[]=new int[6];
if(x+1>=ar.length){
break;
}
else{
c[x]=ar[x+1]-ar[x];
System.out.print(c[x]+" ");
ar[x]=c[x];
}
x++;
}
System.out.println();
}
public static void main(String args[]){
patt ob=new patt();
System.out.println("2 6 12 20 30 42");
for(int a=0;a<6;a++){
ob.pattern();
}
}
}
The output is as follows,
2 6 12 20 30 42
4 6 8 10 12
2 2 2 2 30
0 0 0 28 12
0 0 28 -16 30
0 28 -44 46 12
28 -72 90 -34 30