About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Tuesday, July 26, 2011

***sorting the Array***


//sorting the Array


import java.io.*;
import java.util.*;
class SortingArray
{
public static void main(String aa[])throws IOException
{
int arr[]=new int[10];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter 10 elements in Array...");
for(int i=0;i<10;i++)
{
arr[i]=Integer.parseInt(br.readLine());


}


Arrays.sort(arr);


System.out.println("Sorted elements in Array...");
for(int i=0;i<10;i++)
{
System.out.println(" "+arr[i]);


}



}
}


Output


--Addition and Multiplication of Two Matrices A and B--


//Addition and Multiplication of Two Matrices A and B


import java.io.*;


class MatrixAddition
{
public static void main(String aa[]) throws Exception
{
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please Enter 9 Elements in Matrix A:-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
A[i][j]=Integer.parseInt(br.readLine());


}
}


System.out.println("Please Enter 9 Elements in Matrix B:-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
B[i][j]=Integer.parseInt(br.readLine());


}
}

//Addition of A and B
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j]+B[i][j];


}
}


System.out.println("Addition of Two Matrices is :-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}




//Multiplication of A and B

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=0;
for(int k=0;k<3;k++)
{
C[i][j]=A[i][k]*B[k][j]+C[i][j];
}
}
}


System.out.println("Multiplication of Two Matrices is :-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}











}
}
Output




**Demo of Abstract Class and Methods**


//Demo of Abstract Class and Methods


abstract class A
{
abstract void show();
void display()
{
System.out.println("This is display() method of Abstract class A...");
}
}


class B extends A
{
void show()
{
System.out.println("This is Overridden Method show() of class A in class B...");
}

}


class AbstractDemo
{
public static void main(String aa[])
{
B b=new B();
b.show();
       b.display();
}
}


Output




Monday, July 25, 2011

***Swapping of two numbers***


//Swapping of two numbers
public class Swapping
{
public static void swap(int i,int j)
{
    int temp=i;
    i=j;
    j=temp;
    System.out.println("After swapping i = " + i + " j = " + j);
  }
  
public static void main(String[] args)
{
    int i=1;
    int j=2;
  
  System.out.println("Before swapping i="+i+" j="+j);
    swap(i,j);
  
  }
}


Saturday, July 23, 2011

***Creating Shapes in Applet***


import java.applet.*;
import java.awt.*;

public class  ShapColor extends Applet
{
  int x=300,y=100,r=50;

  public void paint(Graphics g)
  {
  g.setColor(Color.red);  //Drawing line color is red
  g.drawLine(3,300,200,10);
  g.setColor(Color.magenta);
  g.drawString("Line",100,100);

  g.drawOval(x-r,y-r,100,100);
  g.setColor(Color.yellow);  //Fill the yellow color in circle
  g.fillOval( x-r,y-r, 100, 100 );
  g.setColor(Color.magenta);
  g.drawString("Circle",275,100);
 
  g.drawRect(400,50,200,100);
  g.setColor(Color.yellow);  //Fill the yellow color in rectangel
  g.fillRect( 400, 50, 200, 100 );
  g.setColor(Color.magenta);
  g.drawString("Rectangle",450,100);
  }
}


***Palindrome Checking for Numbers***


import java.io.*;

public class Palindrome
{
public static void main(String [] args)
{
  try
{
  BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter number");
  int num= Integer.parseInt(object.readLine());
  int n = num;
  int rev=0;
  System.out.println("Number: ");
  System.out.println(" "+ num);
  for (int i=0; i<=num; i++)
{
  int r=num%10;
  num=num/10;
  rev=rev*10+r;
  i=0;
  }
  System.out.println("After reversing the number: "+ " ");
  System.out.println(" "+ rev);
  if(n == rev)
{
  System.out.print("Number is palindrome!");
  }
  else
{
  System.out.println("Number is not palindrome!");
  }
  }
  catch(Exception e)
{
  System.out.println("Out of range!");
  }
  }
}


***A Simple Applet Program***


// -------------PersonApplet.java----------

import java.awt.*;
import java.applet.Applet;

public class PersonApplet extends Applet
{

        public void paint(Graphics g)
       {

// draw some people!
g.setColor(Color.red);
drawPerson(g, 50, 380, 200);
g.setColor(Color.cyan);
drawPerson(g, 100, 380, 200);
g.setColor(Color.blue);
drawPerson(g, 150, 380, 300);


}

private void drawPerson(Graphics g, int x, int y, int h)
       {

// Draw head (about a 1/4 of the height in proportion)
g.fillOval(x-h/8, y-h, h/4, h/4);

// Draw body
g.drawLine(x, y-3*h/4, x, y - h/4);

// Draw legs
g.drawLine(x, y-h/4, x-h/8, y);
g.drawLine(x, y-h/4, x+h/8, y);

// Draw arms
g.drawLine(x, y-5*h/8, x-h/8, y-3*h/4);
g.drawLine(x, y-5*h/8, x+h/8, y-3*h/4);

}

}