pyramid

import java.util.*; public class pyramid { public pyramid() { int[][] array = new int[6][6]; array[0][5] = 2; for (int i = 1; i<6; i++){ for(int j = 0; j<6; j++){ try{ if (array[i-1][j]==0 && array[i-1][j+1]!=0){ array[i][j] = 2; }else{ array[i][j] = array[i-1][j] * array[i-1][j+1]; } }catch(Exception e){ array[i][j] = 2; } } } for(int i = 0; i<6; i++){ for(int j = 0; j<6; j++){ System.out.print(array[i][j] + ", "); } System.out.println(""); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.