Java Programs : Star Pyramid, Number Pyramid using Array, Constructor Sample Program
Simple Java Program First of all, how to configure command prompt This image helpful to configure command prompt. 1. STAR PYRAMID program: class Star { public static void main(String args[]) { int a,b; for(a=1;a<=5;a++) { for(b=a;b<=5;b++) System.out.print("*"); System.out.println(); } } } Output: 2. Number Pyramid using Array class Darray { public static void main(String args[])throws Exception { int abc[][]=new int[4][5]; int i,j,k=0; for(j=0;j<5 j="" p=""> { for(i=0;i { abc[i][j]=k; k++; } } for(j=0;j<5 j="" p=""> { for(i=0;i { System.out.print(abc[i][j]+" "); k++; } System.out.println(); } } } Output: 3. Constructor Sample Program: class Box { double l; double w; double h; double vol; Box(double x, double y, double z) { l=x; w=y; h=z; } double Boxvol() { vol=l*w*h; re