Sunday, 19 February 2017

JAVA METHOD OVERLOADING

EXAMPLE OF METHOD OVERLOAING


CLASS Overloading
{  public void sum(int a,int b)
      { System.out.println("sum of two integers is="+(a+b));
      }
    public void sum(float a,float b)
       {
          System.out.println("sum of two float value is="+(a+b));
        }
public static void main(String arg[])
    {  Overloading k=new Overloading();
         k.sum(3,4);
         k.sum(4.3,8.4);
    }
}

The method over loading in java mean we just made more than one method in program of same name and it will execute according to input given or according to condition as show in above example there two method of same name and according to input they both will execute.


OUTPUT OF ABOVE PROGRAM

sum of two integers is=7
sum of two float value is=12.7

PLEASE COMMENT BELOW IF YOU HAVE ANY QUERY


INSERTION SORT



ALGORITHM


1.J=2 TO N
2. key=a[j];
3.  i=j-1;
4.  for i>0 and a[i]>key
5. a[i+1]=a[i];
6. i=i-1;
7. a[i+1]=key;

TIME COMPLEXITY 
BEST CASE=THITA(N)
WORST CASE=THITA(N^2)



How Factorial Program Work

Algorithm
fact(int n)
  { if(n==1)
        return 1;
     else 
    return (n*fact(n-1));
}

lets manually run a program
1.lets take n=3;
2.so the if condition will get false and the program will got to else condition.
3. in else part our n is 3 at present so when we move  on return(3*2) it will execute it and now the value of n is decreased to 2.
4.then again this step will goes on till n==1  and when after that the first condition that is if condition will get true and programe will execute then.