How to write a program for Insertion Sort & Bubble Sort in Core Java ?

Hello Friends, 

Today I will give you an example for writing a program for Insertion Sort. 

Java Code :

public class ins_sort {
public static void main(String[] args) {
int i;
 int a[] = {40,20,60,30,50,10};
System.out.println(” insertion sorting…..nn”); 
System.out.println(“Before the sort:n”);  
 for(i = 0; i < a.length; i++)
System.out.print( a[i]+”  “);
System.out.println();
 insertion_srt(a, a.length);  
 System.out.print(“Values after the sort:n”);  
 for(i = 0; i
 System.out.print(a[i]+”  “);
System.out.println(); 
 }

 public static void insertion_srt(int a[], int n){
 
 for (int i = 1; i < n; i++){
 
 int j = i;
 
 int B = a[i];
 
 while ((j > 0) && (a[j-1] > B)){
 a[j] = a[j-1];
 j–;
 }
 a[j] = B;
 }
 
}
}

Output :

 insertion sorting…..


Before the sort:

40  20  60  30  50  10  
Values after the sort:

10  20  30  40  50  60  



And this example is  for writing a program for Bubble Sort in java.



Java Code :

public class bubble {
static int a[]={40,50,20,10,30,60};
public static void main(String[] args) {
System.out.println(“Before sorting…”);
display();
bubblesort();
System.out.println(“After sorting…”);
display();
}
public static void bubblesort(){
int temp;
for(int i=0;i
{
for(int j=0;j
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
public static void display()
{
for(int i=0;i
System.out.println(” “+a[i]);
}
}
}

Output :

Before sorting…
 40
 50
 20
 10
 30
 60
After sorting…
 10
 20
 30
 40
 50
 60

How to write a program for Method ,print simple array in core java.?

Program for Method demo in core java :

Hello Friends, 

Today I will give you an example for writing a program for display how to use method in core java.

Code:

public class Methoddemo {
public static void main (String[] args)
{
int a=80;
int b=290;
int c=Sum(a,b);
System.out.println(“The sum of “+a+” and “+b+”  is =”+c);
}
public static int Sum(int num1,int num2)
{
int ans;
ans=num1+num2;
return ans;
}

}

Output :

The sum of 80 and 290  is =370

Program for print simple array in core java :

Hello Friends, 

Today I will give you an example for writing a program for print simple array in core java.

Code:

public class sample2darray {

public static void main(String args[])

{

int a[][]=new int [3][3];

int k=1;

System.out.print(“nStoring the numbers in array”);

for(int i=0;i<3 div="" i="">

{
for(int j=0;j<3 div="" j="">

{
a[i][j]=k+1;
k=k+1;
}
}
System.out.println(“nYou have stored…”);
for(int i=0;i<3 div="" i="">

{
for(int j=0;j<3 div="" j="">

{
System.out.print(” “+a[i][j]);
}
System.out.println();
}
}
}

Output :

Storing the numbers in array
You have stored…
 2 3 4
 5 6 7
 8 9 10

Write a program for Linear Searching & Binary Searching Array in Java.

Program for linear searching array in core java :

Hello Friends, 

Today I will give you an example for writing a program for  Linear Search array in core java.

Code :

public class linear {
public static void main(String[] args) {
int a[]={1,4,2,6,-4,8,5};
System.out.println(“The element is at location”+Find(a,4));
System.out.println(“The element is at location”+Find(a,-4));
}
public static int Find(int[]a,int key)
{
int i;
for(i=0;i
{
if(a[i]==key)
return i+1;

}
return i-1;
}

}

Output:

The element is at location2
The element is at location5


Write a program for binary searching array in java :

Hello Friends, 

Today I will give you an example for writing a program for Binary Search array in core java.

Code :

public class binary {

public static void main(String[] args) {

int a[]={10,20,30,40,50,60};
int key=40;
Find(a,0,5,key);

}
public static void Find(int[]a,int low,int high,int key)
{
int mid;
if(low>high)
{
System.out.println(“Please Arrange elements in order…!!!”);
return;
}
mid=(low+high)/2;
if(key==a[mid])
System.out.println(“n the element is at the position=”+(mid+1));
else
if(key
Find(a,low,mid-1,key);
else
if(key>a[mid])
Find(a,mid+1,high,key);
}

}

Output :

 the element is at the position=4

How to write a program for Looping in core Java ?

Program for “while loop” in core java :

Hello Friends, 
 
Today I will give you an example for writing a program for use “while loop” in core java.
 
Code:

public class whiledemo {
public static void main(String args[])
{
int count=1,i=0;
while(count<=9)
{
i=i+1;
System.out.println(“the value of i=”+i);
count++;
}
}
}

output :
 
the value of i=1
the value of i=2
the value of i=3
the value of i=4
the value of i=5
the value of i=6
the value of i=7
the value of i=8
the value of i=9

Program for break statement in core java :

Hello Friends, 
 
Today I will give you an example for writing a program for use “break statement” in core java.
 
Code:
public class breakdemo {
public static void main(String args[])
{
for(int i=1;i<=20;i++)
{
if(i%10==0)
{
System.out.println(“Number”+i+”is divisible by 10”);
break;
}
else
{
System.out.println(“Number “+i+”is not divisible by 10”);
}
}
}
}
 
output :
 
Number 1is not divisible by 10
Number 2is not divisible by 10
Number 3is not divisible by 10
Number 4is not divisible by 10
Number 5is not divisible by 10
Number 6is not divisible by 10
Number 7is not divisible by 10
Number 8is not divisible by 10
Number 9is not divisible by 10
Number10is divisible by 10
 
 

Program for “for loop” in core java :

Hello Friends, 
 
Today I will give you an example for writing a program for use “for loop” in core java.


Code:

public class forloopdemo {

public static void main (String args[])
{
for(int i=0;i<=5;i++)
System.out.println(“The value of i=”+i);
 
}
}
output :
 
The value of i=0
The value of i=1
The value of i=2
The value of i=3
The value of i=4
The value of i=5

How to write a program for Metrix addition,subtraction & multiplication in Java.

Hello Friends, 

Today I will give you an example for writeing the java program for Metrix addition, Metrix subtraction and Metrix Multiplication.


Java code:


          import java.io.IOException;
         public class metrix {
           public static void main(String  args[]) 
    throws IOException {
      int a[][] = {{30,55,29},{54,67,84},{76,89,43}};
      int b[][] = {{4,7,5},{2,6,5},{1,4,8}};
      int c[][] = new int [3][3];
        System.out.println(“THe Matrix A:”);
               for(int i=0;i<3 font="" i="">
                 {
                    for(int j=0;j<3 font="" j="">
                     {
                       System.out.print(” “+a[i][j]);
                      }
                     System.out.println(“n”);
                  }
         System.out.println(“THe Matrix B:”);
         for(int i=0;i<3 font="" i="">
           {
            for(int j=0;j<3 font="" j="">
             {
                System.out.print(” “+b[i][j]);
             }
               System.out.println(“n”);
           }
     char choise;
        System.out.println(“Enter choise: 1)sum ,2)sub ,3)mul. “);
      choise = (char)System.in.read();
      switch(choise)
     {
         case ‘1’:
        {
                    for(int i=0;i<3 font="" i="">
                {
                    for(int j=0;j<3 font="" j="">
                    {
                        System.out.print(” “+(a[i][j]+b[i][j]));
                    }
                    System.out.println(“n”);
                }
         break;
        }
        case ‘2’:
        {
                        for(int i=0;i<3 font="" i="">
                    {
                        for(int j=0;j<3 font="" j="">
                        {
                         System.out.print(” “+(a[i][j]-b[i][j]));
                        }
                        System.out.println(“n”);
                    }
                        break;
        }
         
        case ‘3’:
        {
                   for(int i=0;i<3 font="" i="">
                    {
                        for(int j=0;j<3 font="" j="">
                        { c[i][j]=0;
                            for(int k=0;k<3 font="" k="">
                            {
                            c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
                            }
                        }
                        System.out.println(“n”);
                    }
                   System.out.println(“Multiplication is:”);
                   for(int i=0;i<3 font="" i="">
                    {
                        for(int j=0;j<3 font="" j="">
                        {   
                              System.out.print(” “+c[i][j]);
                        }
                        System.out.println(“n”);
                    }
                        break;
        }
       default:
                return;
      }
    }

      Output :
      
         




}

How to write basic Java programs & switch case Statement in Java.

Simple Java Program :

Hello Friends, 

Today I will give you an example for writing simple core java program.

Code:

public class firstprogram {
public static void main(String args[])
{
System.out.println(“This is my first java program.”);
}
}
Output :
This is my frist java program.

Java program for data type :

Hello Friends, 

Today I will give you an example for writing program for different data types in core java.

Code:

public class datatype {

public static void main(String args[])
{
byte a=10;
short  b=10*149;
int c =10000*149;
long d=10000*1000*149;
double e=99.9999;
char f=’v’;
boolean g=true;
boolean h=false;
System.out.println(“the value of a=”+a);
System.out.println(“the value of b=”+b);
System.out.println(“the value of c=”+c);
System.out.println(“the value of d=”+d);
System.out.println(“the value of e=”+e);
System.out.println(“the value of f=”+f);
f++;
System.out.println(“the value of f after increment f=”+f);
System.out.println(“the value of g=”+g);
System.out.println(“the value of h=”+h);
}
}
Output :
the value of a=10
the value of b=1490
the value of c=1490000
the value of d=1490000000
the value of e=99.9999
the value of f=v
the value of f after increment f=w
the value of g=true
the value of h=false

Java program for Escape Sequences :

Hello Friends, 

Today I will give you an example for writing program for Escape Sequences in core java.

Code:

public class Escapedemo {
public static void main(String args[])
{
System.out.println(“t This is a tab demo”);
System.out.println(“n This is new line demon”);
System.out.println(“\is printed”);
}
}

Output :
This is a tab demo

 This is new line demo

is printed

Java program for do…..while Statement :

Hello Friends, 

Today I will give you an example for writing program for “do…while “statement.

Code:

public class dowhiledemo {

public static void main (String args[])
{
int count=1,i=0;
do
{
i=i+1;
System.out.println(“The value of i=”+i);
count++;
}while(count<=8);
}
}
Output :

The value of i=1
The value of i=2
The value of i=3
The value of i=4
The value of i=5
The value of i=6
The value of i=7
The value of i=8

Java Program for switch case Statement :

Hello Friends, 

Today I will give you an example for writing program for “Switch case” in core java.

Code:

public class switchcasedemo {

public static void main (String args[])
throws java.io.IOException
{
char choice;
System.out.println(“t Program for switch case demo”);
System.out.println(“What is your sex ?”);
System.out.println(“1.male”);
System.out.println(“2.female”);
System.out.println(“3.None of the above”);
System.out.println(“Enter your choice”);
choice=(char)System.in.read();
switch(choice)
{
case’1′ : System.out.println(“You are Male.”);
break;
case’2′ : System.out.println(“You are female.”);
break;
default : System.out.println(“None of the above. :D”);
}
}
}
Output :

Program for switch case demo
What is your sex ?
1.male
2.female
3.None of the above
Enter your choice

CSS Margin

Margin In CSS :

The margin clears an area about an factor (outside the border). The margin does not have a history shade, and is totally transparent.
The utmost effective, proper, base, and left margin can be transformed independently applying split up properties. A shorthand margin property can be applied, to alter all edges at once.

Margin – Individual sides :

it is possible to specify different margins for different sides:

Example :

margin-top:100px;
margin-bottom:100px;
margin-right:50px;
margin-left:50px;

Margin – Shorthand property :

To shorten the code, it is possible to specify all the margin properties in one property. This is called a shorthand property.
The shorthand property for all the margin properties is “margin”:

Example :

margin:100px 50px;

CSS Padding

CSS Padding :

The padding  clears a place around this content (inside the border) of an element. The padding  is afflicted with the back ground color of the element.
The most truly effective, proper, base, and left padding  may be changed individually using split properties. A shorthand padding  property can also be used, to improve all paddings at once.

Padding – Individual sides :

it is possible to specify different padding for different sides:

Example :

padding-top:25px;
padding-bottom:25px;
padding-right:50px;
padding-left:50px;

Padding – Shorthand property :

To shorten the code, it is possible to specify all the padding properties in one property. This is called a shorthand property.
The shorthand property for all the padding properties is “padding”:

Example :

padding:25px 50px;



CSS Outlines

CSS Outline :

An outline is a line that is drawn around elements (outside the borders) to really make the element “stand out“.
Nevertheless, the outline home is distinctive from the border property.
The outline is not part of an element’s sizes; the element’s total width and height is not afflicted with the width of the outline.


CSS Border

Border Color :

The border-color property can be used setting along with of the border. The colour could be set by:

  • title – specify a color title, like “blue”
  • RGB – specify a RGB value, like “rgb(255,0,0)”
  • Hex – specify a hex value, like “#ff0000”

You can also set the border shade to “transparent “.

Example :

p.one
{
border-style:solid;
border-color:blue;
}
p.two
{
border-style:solid;
border-color:#98bf21;
}

Border Width :

The border-width property is employed to set the width of the border.
The width is defined in pixels, or by using among the three pre-defined values: thin, medium, or thick.

Example :

p.one
{
border-style:solid;
border-width:5px;
}
p.two
{
border-style:solid;
border-width:medium;
}

Border – Individual sides :

In CSS it is probable to establish various borders for various factors:

Example :

p
{
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dotted;
border-left-style:solid;
}

The border-style home can have from someone to four values.

  • border-style:dotted solid double dashed;
    • top line is dotted
    • right line is solid
    • bottom line is dual
    • remaining line is dashed
  • border-style:dotted solid double ;
    • top line is dotted
    • right and remaining edges are solid
    • bottom line is dual
  • border-style:dotted solid;
    • top and bottom edges are dotted
    • right and remaining edges are solid
  • border-style:dotted;
    • all four edges are dotted

The border-style home is used in the case above. But, in addition, it works with border-width and border-color.