You are on page 1of 12

Program 1

Aim :- Problem on Linearalgebra.


// multiplication of two metrices
public class Program1 {
public static void main(String[] args)
{
//creating two matrices
int a[][]={{4,2,3},{3,4,5},{2,4,3}};
int b[][]={{4,2,3},{2,4,3},{2,4,3}};
//creating another matrix to store the sum of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//adding and printing addition of 2 matrices
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j]; //use - for subtraction
System.out.print(c[i][j]+" ");
}
System.out.println();//new line
}

}
Output :-
846
588
486
Program 2
Aim :- Problem on ProbabilityTheory.
// This is a program to generate a random number based on probability Desity
function of Spiner.
import java.util.Random;

public class program2 {

static int N = 10;


public static void main(String args[])
{
Random random = new Random();
int p=0;
for(int i=0; i<N; i++)
{
p = random.nextInt(400);
if(p > 360)
System.out.println(1 + " ");
else if(p < 0)
System.out.println(0 + " ");
else
System.out.println(p*0.1/360 + " ");
}
}

}
Output :-

0.019444444444444445
0.05305555555555556
0.08166666666666668
0.08194444444444444
0.07861111111111112
0.07361111111111111
0.003333333333333334
0.017777777777777778
0.06527777777777778
0.08361111111111111
Program 3
Aim :- Problem on Permutations & Combinations
// Program to find Permutations and combinations of given numbers.
import java.util.Scanner;

public class program3 {

public static int fact(int num)


{
int fact=1, i;
for(i=1; i<=num; i++){
fact = fact*i;
}
return fact;
}
public static void main(String args[])
{
int n, r;
Scanner scanner = new Scanner(System.in);

System.out.print("Enter Value of n : ");


n = scanner.nextInt();
System.out.print("Enter Value of r : ");
r = scanner.nextInt();

System.out.print("NCR is " +(fact(n)/(fact(n-r)*fact(r))));


System.out.print("\nNPR is " +(fact(n)/(fact(n-r))));
}

Output :-
Enter Value of n : 5
Enter Value of r : 2
NCR is 10
NPR is 20
Program 4
Aim :- Problem on Derivatives.
// program to find derivatives.
public class program4 {
public String derivative(String number)
{
//get coefficient : everything before x
int coefficient
=Integer.parseInt(number.substring(0,number.indexOf("x")));

//get exponant : everything after ^


int exponent
=Integer.parseInt(number.substring(number.indexOf("^")+1));

int newcoefficient=coefficient*exponent;

exponent=exponent-1;

return newcoefficient+"x^"+exponent;
}

public static void main(String[] args)


{

program4 obj=new program4();//creating of object of class


//obj.derivative("6x^6");
System.out.println("The Derivative of 4x^6 is :"+obj.derivative("4x^6"));
}
}
Output :-
The Derivative of 4x^6 is :24x^5
Program 5
Aim :- Problem on Graphical & Diagrammatic Representation
Program 6
Aim :- Problem on Measures Central Tendency or Dispersion
//
public class program6{

public void calMean()


{
//double[] input=new double[5];
double[] input={10,20,30,40,50};
double n=5,sum=0;
for(int i=0;i<n;i++)
{
sum=sum+input[i];
}
System.out.println("Mean :"+sum/n);
}

public void calMedian()


{
int n=5;
double a[]=new double[n];
a[0]=10;
a[1]=20;
a[2]=30;
a[3]=40;
a[4]=50;
double m=0;
if(n%2==1)
{
m=a[(n+1)/2-1];
}
else
{
m=(a[n/2-1]+a[n/2])/2;
}
System.out.println("Median :"+m);
}

public static void main(String[] args)


{
program6 obj =new program6();
obj.calMean();
program6 obj1 =new program6();
obj1.calMedian();
}

Output :-
Mean :30.0
Median :30.0

You might also like