Java Program for Multiplication of two Matrices

import java.util.Scanner; //import Scanner class in our program

class demo
{
public static void main(String...s)
{
int i,j,m,n,p,q,k;
Scanner sc=new Scanner(System.in); //used to read from keyboard

System.out.print("Enter number of rows and columns of first matrix:");
m=sc.nextInt();
n=sc.nextInt();
System.out.print("Enter number of rows and columns of second matrix:");
p=sc.nextInt();
q=sc.nextInt();

if(n!=p)
System.out.print("\nSorry multiplication can't be done!!");
else
{
int a1[][]=new int[m][n];
int a2[][]=new int[p][q];
int a3[][]=new int[m][q]; //resultant matrix will be of size mxq

System.out.print("\nEnter elements of first matrix:\n");
for(i=0;i<m;++i)
for(j=0;j<n;++j)
a1[i][j]=sc.nextInt();

System.out.print("\nEnter elements of second matrix:\n");
for(i=0;i<p;++i)
for(j=0;j<q;++j)
a2[i][j]=sc.nextInt();

System.out.print("\nMultiplication of Matrices:\n");

for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
    a3[i][j]=0;
for(k=0;k<n;++k)
    a3[i][j]=a3[i][j]+(a1[i][k]*a2[k][j]);

System.out.print(a3[i][j]+" ");
}
System.out.print("\n");
}
}
}
}

Java Program for Multiplication of two Matrices

Java Program for Addition of two Matrices

import java.util.Scanner; //import Scanner class in our program

class demo
{
public static void main(String...s)
{
int i,j,n,m;
Scanner sc=new Scanner(System.in); //used to read from keyboard

System.out.print("Enter number of rows:");
m=sc.nextInt();
System.out.print("Enter number of columns:");
n=sc.nextInt();

int a1[][]=new int[m][n];
int a2[][]=new int[m][n];
int a3[][]=new int[m][n];

System.out.print("\nEnter elements of first matrix:\n");
for(i=0;i<m;++i)
for(j=0;j<n;++j)
a1[i][j]=sc.nextInt();

System.out.print("\nEnter elements of second matrix:\n");
for(i=0;i<m;++i)
for(j=0;j<n;++j)
a2[i][j]=sc.nextInt();

System.out.print("\nAddition of Matrices:\n");

for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
a3[i][j]=a1[i][j]+a2[i][j];
System.out.print(a3[i][j]+" ");
}
System.out.print("\n");
}


}
}

Java Program for Addition of two Matrices

What is Tail Recursion? Example to Explain Tail Recursion?

Tail recursion refers to recursive call at last line. Tail recursion can be eliminated by changing the recursive call to a goto preceded by a set of assignments per function call. This simulates the recursive call because nothing needs to be saved after the recursive call finishes. We can just goto the top of the function with the values that would have been used in a recursive call.

What is Tail Recursion? Example to Explain Tail Recursion?

The recursive function for Tower of Honoi Problem is given below. It is an example of recursive function with tail recursion.


Recursive function TOH with tail recursion

void TOH(int n,char x,char y,char z)
{
                if(n>0)
                {
                                TOH(n-1,x,z,y);
                                printf("\n%c -> %c",x,y);
                                TOH(n-1,z,y,x);                 //tail recursion
                }
}

Without tail recursion

void TOH(int n,char x,char y,char z)
{
                char temp;
                label:

                if(n>0)
                {
                                TOH(n-1,x,z,y);
                                printf("\n%c -> %c",x,y);
                                temp=x;
                                x=z;
                                z=temp;
                                n=n-1;
                                goto label;
                }


}

Watch below video to understand tail recursion easily.



Image source: http://learnyousomeerlang.com/recursion

Java Program to Find Intersection of two Arrays

For example we have two sorted arrays a1[]={2,3,5,11} and a2[]={4,5,7,9,11} then intersection of a1 and a2 will be {5,11}. A Java program for finding intersection of two arrays is given below.

Also Read: Java Program to Find Union of two Arrays

Java Program to Find Intersection of two Arrays

import java.util.Scanner; //import Scanner class in our program

class demo
{
public static void main(String...s)
{
int i,j,n1,n2;
Scanner sc=new Scanner(System.in); //used to read from keyboard

System.out.print("Enter number of elements of first array:");
n1=sc.nextInt();
System.out.print("Enter number of elements of second array:");
n2=sc.nextInt();

int a1[]=new int[n1];
int a2[]=new int[n2];

System.out.print("\nEnter elements of first array in ascending order:");
for(i=0;i<n1;++i)
a1[i]=sc.nextInt();

System.out.print("\nEnter elements of second array in ascending order:");
for(i=0;i<n2;++i)
a2[i]=sc.nextInt();


i=j=0;
System.out.print("\nIntersection of Arrays: ");
while(i<n1&&j<n2)
{
if(a1[i]<a2[j])
i++;
else
if(a2[j]<a1[i])
j++;
else
{
System.out.print(a1[i]+" ");
i++;
j++;
}
}

}
}

Java Program to Find Intersection of two Arrays

Java Program to Find Union of two Arrays

For example we have two sorted arrays a1[]={2,3,5,11} and a2[]={4,7,9} then union of a1 and a2 will be {2,3,4,5,7,9,11}. A Java program for finding union of two arrays is given below.

Also Read: Java Program to Find Smallest and Largest Element in an Array

Java Program to Find Union of two Arrays

import java.util.Scanner; //import Scanner class in our program

class demo
{
public static void main(String...s)
{
int i,j,n1,n2;
Scanner sc=new Scanner(System.in); //used to read from keyboard

System.out.print("Enter number of elements of first array:");
n1=sc.nextInt();
System.out.print("Enter number of elements of second array:");
n2=sc.nextInt();

int a1[]=new int[n1];
int a2[]=new int[n2];

System.out.print("\nEnter elements of first array in ascending order:");
for(i=0;i<n1;++i)
a1[i]=sc.nextInt();

System.out.print("\nEnter elements of second array in ascending order:");
for(i=0;i<n2;++i)
a2[i]=sc.nextInt();


i=j=0;
System.out.print("\nUnion of Arrays: ");
while(i<n1&&j<n2)
{
if(a1[i]<a2[j])
{
System.out.print(a1[i]+" ");
i++;
}
else
if(a2[j]<a1[i])
{
System.out.print(a2[j]+" ");
j++;
}
else
    {
System.out.print(a1[i]+" ");
     i++;
     j++;
    }
}

if(i<n1)
while(i<n1)
{
System.out.print(a1[i]+" ");
i++;
}

if(j<n2)
while(j<n2)
{
System.out.print(a2[j]+" ");
j++;
}

}
}


Java Program to Find Union of two Arrays

Java Program to Find Smallest and Largest Element in an Array

import java.util.Scanner; //import Scanner class in our program

class demo
{
public static void main(String...s)
{
int i,n,large,small;
Scanner sc=new Scanner(System.in); //used to read from keyboard

System.out.print("Enter number of elements:");
n=sc.nextInt();
int a[]=new int[n];

System.out.print("\nEnter elements of Array:");
for(i=0;i<n;++i)
a[i]=sc.nextInt();

large=small=a[0];
for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
}

System.out.print("\nSmallest Element:"+small);
System.out.println("\nLargest Element:"+large);
}
}

Java Program to Find Smallest and Largest Element in an Array

An Insight into Apple iMovie app and its New Version 10.0.4

Apple rolled out a new version update for iMovie – an innovative iOS app development for Mac. The new 10.0.4 version will help resolve crashing issues that caused iMovie app to quit unexpectedly.

An Insight into Apple iMovie app and its New Version


Before getting in depth into the new updated version of the iMovie application, let's have a detailed insight about this app and its previous version.

Introduction to iMovie and It's Features


If you've been yearning for a gratifying video recording experience for Mac, then iMovie is an app that you can't miss to have. It lets you put the entire focus on videos and enjoy watching them like never before. With this app you browse through video library, organize them all at one place, create high-definition movies and trailers, and even allow sharing your beautiful moments instantly. It's available for $4.99 in the iTunes store.

Introduction to iMovie and It's Features


The best part about using the app is that all your work carried out on iMovies gets saved automatically at the same time as you work. So, you no longer have to fret about constantly saving your work. What's more? The app helps to improvise the visual appeal as well sound of your video. Also, it helps in augmenting your video using the colour controls. Let's have a more detailed view on the features of this application.

Introduction to iMovie and It's Features

Hollywood-style trailers: With iMovie you get the flexibility to choose the most suitable template from 29 templates – for creating your movie trailer in Hollywood style. All the templates come enriched with high-end graphics and original scores of renowned film composers. So, what're you waiting for? Pick the best videos and photos for constructing your video trailers and fulfil your urge to develop your own hollywood-styled trailers.

Beautiful HD movies: In the iMovie app you get 15 unique themes with various customization options, which include transitions, titles, ability to adjust motion effects (like speed up, slow down and fast-forward) and more. That's not it! You can even build your own soundtrack using the songs from the Apple's iTunes library and so on.

iMovie Theatre: Now you can show movies as well as trailers you’ve made with help of your own personal theatre. Your movies will serve as beautiful posters, which you can click to watch the clips in full-screen.

Sharing is Fun: iMovie app allows sharing your video clips with friends and family. It even let you post your clips to YouTube and Vimeo. You can even share the clips via emails.

Experienced video editors won't find any difficulty in working with the iMovie application. However, proficient iPhone App Developer for Hire can be availed, in case you find some technical issues. But even immature and neophyte video editors won't find it hard to create video clips and photos using the app in not more than 10 minutes, after doing a little practice and understanding the settings.

What has iMovie version 10.0.4 in Store for You?


As discussed earlier, iMovie version 10.0.4 is new update that has recently been released. The major purpose behind updating the existing version was to fix bug issues and bring stability improvements with the previous iMovie app version. Prior to this update, iMovie for Mac was updated to 10.0.3 version in April that introduced new sort features in the sidebar, tweaked user interface, and upgraded font options and color in new titles etc. But unfortunately, even the last version failed to fix the issues that led to force close iMovie.

What has iMovie version 10.0.4 in Store for You?

With 10.0.4 version, Apple's effort to eliminate bugs from the app has proved a success. Any existing iMovie app users can easily download the upgraded version of the application from the Mac App for free. However, new users will have to purchase it for $14.99.


Let's Wrap Up!


If you have been craving to create simple yet stunning video clips that can make the eye-balls roll, then the latest iMovie 10.0.4 version for Mac OS X seems to be the perfect choice for you. Though, nothing much has been added to this update but it's a very important one from all the previous upgrades made to the application, as it resolved the bug issues and stability problems that made the app to quit, without any prior warning. So, begin adding your pics and videos and build some really fascinating movies showing off your talent as a movie director – to your friends, family and acquaintances.

Author Bio:
Rick Brown is a veteran technical content writer associated with a reputed iPhone Application Development India firm – Mobiers Ltd. You can avail iPhone App Developer for Hire, in case you are looking forward for the same.

Website: http://www.mobiers.com
Facebook: https://www.facebook.com/Mobiers

Compiler Vs Interpreter: Difference between Compiler and Interpreter

Compiler Vs Interpreter

Compiler

1. Compiler takes the source program written in higher level language and translate whole program into a machine language.

2. A compiler program reads through the entire high-level language source program, and in two or more passes through it, translate it all to relocatable machine code programs (object module). Linker links these relocatable object modules. The output file from the linker is then located to get absolute address. Finally located program is loaded into memory. Once the located program is loaded in memory, the entire program can be run without any further translation. Therefore, it will run much faster than it would if executed by an interpreter.

3. C and C++ programs are executed in this way.

4. The major disadvantage of the compiler approach is that when an error is found, it usually must be corrected in the source program and the entire compile-load sequence repeated.

Compiler Vs Interpreter: Difference between Compiler and Interpreter

Interpreter

1. At a time, an interpreter executes one statement of the higher level language.

2. The interpreter reads a high level language statement of the source program, translates the statement into machine code and, if it doesn’t need information from another instruction, executes the code for that statement immediately. It then reads the next high level language source statement, translate it, and executes it.

3. BASIC programs are often executed in this way.

4. The advantage of using interpreter is that if an error is found, you can just correct the source program and immediately rerun it.


5. The major disadvantage of interpreter approach is that an interpreted program runs 5 to 25 times slower than the same program will run after being compiled. The reason is that with an interpreter each statement must be translated to machine code every time the program is run.

Compiler Vs Interpreter: Difference between Compiler and Interpreter


Lets understand about compiler vs interpreter from below video.