Method Overloading

import java.util.*;
import java.io.*;
class Overloading
{
 
 void Test()
 {
  System.out.println("No. Parameters::");
 }
 void Test(int a)
 {
  System.out.println("a:"+a); 
 }
 void Test(int a,int b)
 {
  System.out.println("a and b:"+a+" "+b);
 }
 double Test(double a)
 {
  System.out.println("double a::"+a);
  return a*a;
 }
 

 
}
class Overload
{
 public static void main(String args[])
 {
  Overloading o1=new Overloading();
  double result;
  o1.Test();
  o1.Test(10);
  o1.Test(10,20);
  result=o1.Test(123.25);
  System.out.println("result:::"+result);
 }
}
Output:

Addition of Two Matrix.

import java.util.Scanner;
class AddTwoMatrix
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n  = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix");
for (  c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
first[c][d] = in.nextInt();
System.out.println("Enter the elements of second matrix");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
second[c][d] = in.nextInt();
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d];  //replace '+' with '-' to subtract matrices
System.out.println("Sum of entered matrices:-");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
System.out.print(sum[c][d]+"\t");
System.out.println();
}
}
}


output:


/*2D Rotation program in computer graphics in c with output*/


2D Rotation Algorithm
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>


void rotate( int figure[], int edges, double angle, int cx, int cy )
{
      double x, y;
      angle = -1 * (angle*3.14/180);
      double cos_a = cos(angle);
      double sin_a = sin(angle);

      for(int i=0; i < edges; i++)
      {
            x = figure[2*i] - cx;
            y = figure[2*i+1] - cy;
            figure[2*i] = ceil( (* cos_a) - (* sin_a) + cx );
            figure[2*i+1] = ceil( (* sin_a)+(* cos_a) + cy );
      }
}

void main()
{
      int figure[20], edges;  // A Figure with Max 10 edges.
      double angle;
      int cx=0, cy=0;
      int gd = DETECT, gm;
      initgraph( &gd, &gm, "" );
      int max_y = getmaxy();
      clrscr();
      cleardevice();

      printf( "Number of edges: " );
      scanf( "%d", &edges );

      for(int i=0; i < edges; i++)
      {
            printf( "Enter edge (x%d,y%d) : ", i , i );
            scanf( "%d %d", &figure[2*i], &figure[2*i+1] );
      }
      figure[2*i] = figure[0];
      figure[2*i+1] = figure[1];
      edges += 1;

      printf( "Enter angle of rotation in degrees: ");
      scanf( "%lf", &angle);

      printf( "Enter the center of rotation: \n");
      printf( "cx: ");
      scanf( "%d", &cx);
      printf( "cy: ");
      scanf( "%d", &cy);
      cy = max_y - cy;

      cleardevice();
      setbkcolor(WHITE);

      setcolor(GREEN);
      setlinestyle(SOLID_LINE, 0, 3);
      drawpoly( edges, figure );
      getch();

      for(int i=0; i < edges; i++)
            figure[2*i+1] = max_y - figure[2*i+1];
      rotate(figure,edges,angle,cx,cy);
      for(int i=0; i < edges; i++)
            figure[2*i+1] = max_y - figure[2*i+1];

      setcolor(RED);
      drawpoly( edges, figure );
      getch();
}


/*Function:
void rotate( int figure[], int edges, double angle, int cx, int cy )
{
      double x, y;
      angle = -1 * (angle*3.14/180);
      double cos_a = cos(angle);
      double sin_a = sin(angle);

      for(int i=0; i < edges; i++)
      {
            x = figure[2*i] - cx;
            y = figure[2*i+1] - cy;
            figure[2*i] = floor( (* cos_a) - (* sin_a) + cx + 0.5 );
            figure[2*i+1] = floor( (* sin_a)+(* cos_a) + cy + 0.5 );
      }
} */
Output:
1.Enter Co-ordinates
2.Actual Image

3.Rotating Image


/*Boundry Fill Algorithm in Computer graphics with output*/

Boundry Fill Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void boundary_fill(int x, int y, int fcolor, int bcolor)
{

    if ((getpixel(x, y) != fcolor) && (getpixel(x, y) != bcolor)) {
       putpixel(x, y, fcolor);
       boundary_fill(x + 1, y, fcolor, bcolor);
       boundary_fill(x - 1, y, fcolor, bcolor);
       boundary_fill(x, y - 1, fcolor, bcolor);
       boundary_fill(x, y + 1, fcolor, bcolor);
       boundary_fill(x + 1, y - 1, fcolor, bcolor);
       boundary_fill(x + 1, y + 1, fcolor, bcolor);
       boundary_fill(x - 1, y - 1, fcolor, bcolor);
       boundary_fill(x - 1, y + 1, fcolor, bcolor);
    }
}


void main()
{
    int x, y, fcolor, bcolor;

    clrscr();
    printf("Enter the seed point (x,y) : ");
    scanf("%d%d", &x, &y);
    printf("Enter boundary color : ");
    scanf("%d", &bcolor);
    printf("Enter new color : ");
    scanf("%d", &fcolor);

    int gd = DETECT, gm = DETECT;
    initgraph(&gd, &gm, "");
    cleardevice();
    boundary_fill(x, y, fcolor, bcolor);

    getch();
}




Output: