Friday 7 August 2015

How to make a div scroll-able?



To make div horizontally scroll-able add overflow-x:scroll style to div as:


<div style="overflow-x: scroll; width: 300px;">
In HTML, span and div elements are used to define parts of a document so that they are identifiable when no other HTML element is suitable.
<div>




To make div vertically scroll-able add overflow-y:scroll style to div as:


<div style="overflow-y: scroll; height: 300px;">
In HTML, 
span and div elements are used 
to define parts of a document 
so that they are identifiable 
when no other HTML element is suitable. 
<div>


To make div  scroll-able both horizontally & vertically then  add overflow:scroll style to div as:


<div style="overflow: scroll; height: 300px; width:400px;">
In HTML, 
span and div elements are used 
to define parts of a document 
so that they are identifiable 
when no other HTML element is suitable. 
<div>

Thursday 6 August 2015

Add Lyrics to mp3 file using Windows Media Player in simple steps



Download the Lyrics Plugin for Windows Media Player from www.lyricsplugin.com

Install it and play any song.

Click [Search Google] to find the lyrics of that song. Copy the lyrics.

Click [Edit] and paste the copied lyrics in lyrics textbox, you can also change the Title and Artist.
Click Save Changes

Now whenever you open that song you can see the lyrics of that song

Tuesday 4 August 2015

Applet Demo 1



Source Code:


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


public class Demo1 extends Applet
{
    public void init()
    {
        //Code to run automatically
        this.setSize(500, 500);
        this.setBackground(Color.CYAN);
    }
    public void paint(Graphics g)
    {
        
        
        //now draw graphics
        g.drawLine(0, 0, 100, 100);
        g.drawRect(0, 0, 100, 100);
        
        //change color of graphics
        g.setColor(Color.blue);
        g.drawString("Applet Demo", 0, 120);
    }
}

Monday 3 August 2015

Getting Started with Java GUI Programming



Download the Netbeans IDE from filehippo.com/download_netbeans

Also download Java JDK(32-bit or 64-bit) according to your operating system. For 32-bit operating system download the 32-bit version of Java JDK and for 64-bit operating system download the 64-bit version of Java JDK

After downloading firstly install Java JDK and then Netbeans

Sunday 2 August 2015

Binary Search Program



#include<iostream.h>
#include<conio.h>
void main()
{ 
 clrscr();
int n,*a,item,loc=-1;
cout<<"\nenter the no. of elements :";
cin>>n;
a=new int[n];  //dynamically initialize array
cout<<"\nenter the elements:\n";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"\nenter the element you want to search: ";
cin>>item;
int mid,end=n,beg=0;
while(beg<=end&&loc==-1)
{
 mid=(beg+end)/2;
 if(a[mid]==item)
  loc=mid; 
 else if(a[mid]<item)
  beg=mid+1;
 else
  end=mid-1;
}
if(loc!=-1)
      cout<<"\nlocation of "<<item<<" is:"<<loc+1;
else
      cout<<"\n"<<item<<" not found!!!";
getch();
}

Linear Search Program



#include<iostream.h>
#include<conio.h>
void main()
{     clrscr();
int  *a,n,loc=-1,item;
cout<<"\nenter the no. of elements (max. 10):";
cin>>n;
a=new int[n];  //dynamically initialize array
cout<<"\nenter the elements:\n";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"\nenter the element to be searched: ";
cin>>item;
for(i=0;i<n;i++)
      if(a[i]==item)
      {      loc=i;
             break;    
      }
if(loc==-1)
     cout<<"\n"<<item<<" not found!!!";
else
     cout<<"location of "<<item<<" is: "<<loc+1;
getch();
}

Selection Sort Program



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,temp,min;
cout<<"\nEnter the no. of elements you want:";
cin>>n;
int *a=new int[n];  //dynamically initialize array
cout<<"\nEnter the elements:\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
 min=i;
 for(int j=i+1;j<n;j++)
 {
  If(a[min]>a[j])
   min=j;
 }
 temp=a[min];
 a[min]=a[i];
 a[i]=temp;
}
cout<<"\nSorted list of given integers is(in ascending order) :\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}



Bubble Sort Program


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,temp;
cout<<"\nEnter the no. of elements you want:";
cin>>n;
int *a=new int[n];  //dynamically initialize array
cout<<"\nEnter the elements:\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
 for(int j=0;j<n-i-1;j++)
 {
  if(a[j]>a[j+1])
  {
   temp=a[j];
   a[j]=a[j+1];
   a[j+1]=temp;
  }
 }
}
cout<<"\nSorted list of given integers is(in ascending order) :\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}



Merge Sort Program


#include<iostream.h>
#include<conio.h>
#include<values.h>
void merge(int a[],int p,int q,int r)
{
 int n1=q-p+1,n2=r-q;
 int *l=new int[n1+1];
 int *rt=new int[n2+1];
 for(int i=0;i<n1;i++)
       l[i]=a[p+i];

 for(int j=0;j<n2;j++)
  rt[j]=a[q+j+1];  
 l[n1]=MAXINT;   //SENTINEL
 rt[n2]=MAXINT;  //SENTINEL
 i=j=0;
 for(int k=p;k<=r;k++)
 {
  if(l[i]<=rt[j])
  {
   a[k]=l[i];
   i+=1;
  }
  else
  {
   a[k]=rt[j];
   j+=1;
  }
 }
}
void mergesort(int a[],int p,int r)
{
 int q;
 if(p<r)
 {
  q=(p+r)/2;
  mergesort(a,p,q);
  mergesort(a,q+1,r);
  merge(a,p,q,r);
 }
}
void main()
{
 clrscr();
 int n;
 cout<<"\nEnter the no. of elements you want:";
 cin>>n;
 int *a=new int[n];  //dynamically initialize array
 cout<<"\nEnter the elements:\n";
 for(int i=0;i<n;i++)
  cin>>a[i];

 mergesort(a,0,n-1);
 cout<<"\n\nSORTED ARRAY IS:\n";
 for( i=0;i<n;i++)
  cout<<a[i]<<" ";
 getch();
}



Quick Sort Program




#include<iostream.h>
#include<conio.h>
int partition(int a[],int p,int r)
{
int x,i,temp;
x=a[r];
i=p-1;
for(int j=p;j<r;j++)
{
   if(a[j]<=x)
   {
   i=i+1;
   temp=a[j];
   a[j]=a[i];
   a[i]=temp;
   }
}
temp=a[i+1];
a[i+1]=a[j];
a[j]=temp;
return i+1;
}
void quicksort(int a[],int p,int r)
{
int q;
  if(p<r)
  {
   q=partition(a,p,r);
   quicksort(a,p,q-1);
   quicksort(a,q+1,r);
  }
}
void main()
{
clrscr();
int *a,n;
cout<<"\nEnter the no. of element you want:";
cin>>n;
a=new int[n];  //dynamically initialize array
cout<<"\nEnter the elements:\n";
for(int i=0;i<n;i++)
 cin>>a[i];
quicksort(a,0,n-1);
cout<<"\nSorted Array is:\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}

Heap Sort Program


#include<iostream .h>
#include<conio .h>
int heapsize,length;
void exchange(int &a,int &b)
{
 int temp;
 temp=a;
 a=b;
 b=temp;
}
void maxheapify(int a[],int i)
{
 int l,r,largest,temp;
 l=2*i;               //left[i]
 r=2*i+1;         //right[i]
 if(l<=heapsize&&a[l]>a[i])
  largest=l;
 else
  largest=i;

 if(r<=heapsize&&a[r]>a[largest] )
  largest=r;
 if(largest!=i)
  {
  exchange(a[i],a[largest]);
   maxheapify(a,largest);
  }
}
void buildmaxheap(int a[])
{
 heapsize=length;
 for(int i=length/2;i>=1;i--)
  maxheapify(a,i);
}
void heapsort(int a[])
{
 buildmaxheap(a);
 for(int i=length;i>=2;i--)
 {
  exchange(a[1],a[i])  ;
  heapsize-=1;
  maxheapify(a,1);
 }
}
void main()
{
clrscr();
int *a,n;
cout<<"\nEnter the no of element you want(max 20):";
cin>>n;
length=n;
a=new int[n+1];   //DYNAMICALLY INITIALISE ARRAY,AS ARRAY MUST START FROM INDEX 1 SO SIZE IS (N+1)
cout<<"\nEnter the elements:\n";
for(int i=1;i<=n;i++)
 cin>>a[i];
heapsort(a);
cout<<"\nSorted Array is:\n";
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
getch();
}

Computer Peripherals & Interfaces (CPI) Notes

Computer Graphics Notes

Remove all hyperlinks from a word file

  1. To remove a single hyperlink without losing the display text or image, right-click the hyperlink, and then click Remove Hyperlink. To remove all hyperlinks in a document, press CTRL+A to select the entire document and then press CTRL+SHIFT+F9.

Learn Java Part 11

for each loop in java



What is for each loop?

for each loop in java is the enhanced version of for loop. It is introduced from JDK 5. It is used to iterate all elements of an array or Collection.




Syntax:



for ( data-type variableName :  array or collection )

{

    //statements

}


Consider the following program:

public class ForEachLoop
{
    public static void main(String[] args)
    {
        int[] array ={ 1, 2, 3, 4, 5 };
        System.out.println("Array elements: ");

        for(int element: array)
               System.out.print(element+"  ");

    }
}



Write the above program in Notepad and save it as ForEachLoop.java 

Compile and run it to get the following output:



Array elements: 

1  2  3  4  5



the loop for(int element: array)

fetches the elements of array and assign it to variable element so we can use element to access the elements of array



Consider the following program to access elements of multi-dimensional array



public class ForEachLoop
{
    public static void main(String[] args)
    {
     int[][] array ={ {1, 2, 3, 4,},{ 5,6,7,8} }; //array with 2 rows and 4 columns
        System.out.println("Array elements: ");
        for(int[] row: array)
            for(int element: row)
               System.out.print(element+"  ");
    }
}

Write the above program in Notepad and save it as ForEachLoop.java 

Compile and run it to get the following output:



Array elements: 

1  2  3  4  5  6  7  8



the loop for(int[ ] row: array)

fetches one row of array and assign it to variable row so we can use row to access one row(or one dimensional array) of array



the loop for(int element: row)

fetches the elements of row and assign it to variable element so we can use element to access the elements of row

Command Line Arguments




public class CommandLineArguments
{
    public static void main(String[] args)
    {
        System.out.println("Total number of Command Line Arguments: "+args.length);
        System.out.println("Command Line Arguments:");
        for(int i=0;i<args.length;i++)
            System.out.println(args[i]);
    }
}


Type the above program in Notepad and Save it as CommandLineArguments.java

Compile like this:



javac  CommandLineArguments.java



Run like this:



java  CommandLineArguments   Arguments



For example: 


java  CommandLineArguments   Hello World

output:



Total number of Command Line Arguments: 2

Command Line Arguments:

Hello

World






If you run like this:

java  CommandLineArguments

output:



Total number of Command Line Arguments: 0

Command Line Arguments:






Note: Each argument in command line arguments is seperated by a space

Learn Java Part 10