JAVA

This section of JAVA contains source codes of many different type of Java Programs to learn the JAVA Basics. These Programs are well formatted and easy to understand.

JAVA

Postby aman_1982_2006 on August 30th, 2008, 6:35 am

Code: Select all
//use of constructors
class shape
{
   int l,b,h;
   shape()//DEAFULT CONSTRUCTORS
   {
      l=1;
      b=1;
      h=1;
   }
   shape(int x,int y,int z)//PARAMETERIZED CONSTRUCTOTS
   {
      l=x;
      b=y;
      h=z;
   }
   float volume()
   {
      return l*b*h;
   }

}
class vol
{
   public static void main(String ar[])
   {
      float a1;
      shape s1=new shape();
      a1=s1.volume();      
      System.out.println(a1);
      shape s2=new shape(4,5,6);
      a1=s2.volume();      
      System.out.println(a1);
   }
}
aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am

Recursion programs in java

Postby aman_1982_2006 on September 25th, 2008, 9:55 am

Code: Select all
//prog to calculate fibo of a no using recursion
class fib
{
   int f(int n)
   {
      if(n==1)
         return 0;
      else if(n==2)
         return 1;
      else
         return (f(n-2)+f(n-1));
   }
}
class fibo
{
   public static void main(String ar[])
   {
      fib f1=new fib();
      for(int i=1;i<10;i++)
      {
      int an=f1.f(i);
         System.out.println("series "+an);
      }
   }
}
      
aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am


Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests