Saturday 31 October 2015

MATRIX MULTIPLICATION



A- Rows in first Matrix
B- Columns for first  Matrix and Rows for Second Matrix
C- Columns for Second Matrix


package com.talent;

import java.util.Scanner;

public class MatrixMulti {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
  System.out.println("enter the rows for first matrix");
   int A=sc.nextInt();
 System.out.println("enter the no. for  columns  in first matirx / rows in second matrix ");
   int B=sc.nextInt();
   System.out.println("enter the columns in second matrix");
   int C=sc.nextInt();
 
 
   //now define all three matrix
       int [][]matrix1= new int[A][B];
       int [][]matrix2= new int[B][C];
       int [][]product= new int[A][C];
     
     
       System.out.println("enter the data for first elements");
     
       for(int i=0; i<A; i++)
       {
        for(int j=0; j<B; j++)
        {
        matrix1[i][j]=sc.nextInt();
        }
       
       }
 
     
      System.out.println("enter the data of second");
                for(int i=0; i<B; i++)
                {
                for(int j=0; j<C; j++)
               
                {
                matrix2[i][j]=sc.nextInt();
               
                }
               
                }
               
     
      System.out.println("first matirx is : ");
      for(int i=0; i<A; i++)
      {
     for(int j=0;j<B;j++)
     {
     System.out.print(matrix1[i][j]+"\t");
   
     }
     
     System.out.println();
      }
   System.out.println("second matirx is: ");
       for(int i=0; i<B; i++)
       {
        for(int j=0; j<C; j++)
       
        {
       System.out.print(matrix2[i][j]+"\t");
        }
        System.out.println();
       }
 
     
       System.out.println("PRODUCT IS : ");
       for(int i=0; i<A;i++)
       {
        for(int j=0; j<C; j++)
        {
       
        for(int k=0; k<B;k++)
        {
        product[i][j] += matrix1[i][k] * matrix2[k][j];
       
        }
        }
       
       }
 
   for(int i=0; i<A; i++)
   {
    for(int j=0; j<C; j++)
    {
    System.out.print(product[i][j]+"\t");
   
    }
    System.out.println();
   }
 
 

}

}

OUTPUT->enter the rows for first matrix
2
enter the no. for  columns  in first matirx / rows in second matrix
3
enter the columns in second matrix
2
enter the data for first elements
3
4
5
6
7
8
enter the data of second
3
4
5
6
7
8
first matirx is :
3 4 5
6 7 8
second matirx is:
3 4
5 6
7 8
PRODUCT IS :
64 76
109 130







Simple Matrix Programs

                                                                           Simple  Matrix

package com.talent;

import java.util.Scanner;

public class Matrix1 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
System.out.println("enter the no. of rows");
int row=sc.nextInt();

System.out.println("enter the no. of columns");
 int column=sc.nextInt();

 //now define 2D array to hold the matirx

 int[][]matrix=new int[row][column];

 System.out.println("enter the data");
           
 for(int i=0;i<row;i++)
 {
 for(int j=0; j<column; j++)
 {
 matrix[i][j]=sc.nextInt();

 }


 }

System.out.println("MATRIX IS :  ");

for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
System.out.print(matrix[i][j]+"\t");
}
System.out.println();
}


}

}


OutPut->enter the no. of rows
3
enter the no. of columns
2
enter the data
4
5
6
7
8
9
MATRIX IS :
4 5
6 7
8 9






Friday 30 October 2015

Sorting String


                                                       Sorting String


package com.talent;

public class SortString {

public static void main(String[] args) {

   String []names={"Amit","neeraj","dhiraj","SHIPRA","azak","axdf"};
 
     sortStringBubble(names);
   
     for(int k=0;k<6;k++)
     {
   
    System.out.println(names[k]);
   
   
     }

}

private static void sortStringBubble(String[] x) {


boolean flag=true;

String temp;

while (flag) {


flag=false;

for (int j = 0; j < x.length-1; j++) {

if(x[j].compareToIgnoreCase(x[j+1])>0)

{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
flag=true;

}
}

}


}

}
OutPut->
Sorted String
Amit
axdf
azak
dhiraj
neeraj
SHIPRA

Find Character's Frequency


                                              Find Character's Frequency


package com.talent;

public class Find_Character_Frequency {


static int [] characterFrequency(String s)

  {

       s=s.toLowerCase();

    int frequency[]=new int[26];

   for (int i = 0,c=97; i < 26; i++,c++)

   {

   for (int j = 0; j < s.length(); j++)


     {

   char ch=s.charAt(j);

   

                   if(ch==c)
                  frequency[i]++;


} }
return frequency;
  }

 public static void main(String[] args) {



 String s="I am Java Developer";

 int frequency[]=characterFrequency(s);
 System.out.println("Albhabet \t Frequency");


 for (int i = 0,c=97; i <26; i++,c++) {
 if(frequency[i]!=0){
 char ch=(char)c;

 System.out.println(ch+"\t\t"+frequency[i]);


 }

}

}


}
OutPut->
Albhabet Frequency
a 3
d 1
e 3
i 1
j 1
l 1
m 1
o 1
p 1
r 1
v 2

Duplicate Elements in Java


                                                            




package com.talent;



public class Dublicate_Element {


public static void main(String[] args) {
         

        int A[]=new int[]{1,2,3,4,5,6,7,8,9}; //take element in array
int B[]=new int[A.length*2];      // here we double the size of array
     for (int i = 0,k=0; i < A.length; i++,k++)
           {
            B[k]=A[i];
            B[++k]=A[i];
          

  }
      for (int i = 0; i < B.length; i++) 
            {
   System.out.println(B[i]);
          }
}
}


OuTPuT->112233445566778899

How can increase and decrease the fonts in eclipse

                               How can increase and decrease the fonts in eclipse


Simple Steps for it--

Go to Install New Software

put it and download,


http://eclipse-fonts.googlecode.com/svn/trunk/FontsUpdate/

click ok and you will see two button on eclipse.