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;
return(vol);
}
}
class Rectanglevolume
{
public static void main(String args[])
{
Box bx=new Box(10,10,10);
double vol1=bx.Boxvol();
System.out.println("volum="+vol1);
}
}

Output:



Comments

Popular posts from this blog

Angular 4 + Cordova Boilerplate ::: Hybrid Mobile Application

In MVC 4 Save and Retrieve cookies