Java Assignment 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ASSIGNMENT-3

1.Implement transpose of a given matrix.

public class transposeMatrix {


public static void main(String[] args)
{
//creating a matrix
int a[][]= {{1,3,4},{2,4,3},{3,4,5}};
//creating another matrix to store transpose
int transpose[][]=new int[3][3];

//logic for transpose matrix


for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
transpose[i][j]=a[j][i];
}
}
System.out.println("Matrix without transpose");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.println(a[i][j]+" ");
}
System.out.println(" ");
}
System.out.println("Transpose Matrix is:");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.println(transpose[i][j]+" ");

}
System.out.println();

}
}

}
OUTPUT:

Matrix without transpose

1 3 4

2 4 3

3 4 5

Transpose Matrix is:

1 2 3

3 4 4

4 3 5
2. Implement multiplication of two Matrix

public class Multiplication


{
public static void main(String[] args)
{

int a[][]= {{1,1,1},{2,2,2,},{3,3,3}};


int b[][]= {{1,1,1},{2,2,2},{3,3,3}};

int c[][]=new int [3][3];

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=0;

for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k]*b[k][j];

}//end of k loop

System.out.print(c[i][j]+" ");//printing matrix element


}//end of j loop

System.out.println();
}
}
}

OUTPUT:
666

12 12 12

18 18 18
3. Implement a program to generate random password based on customer name,
age and id for banking applications.
import java.util.*;
//Here we are using random() method of util to generate password

public class Assignment2a


{
public static void main(String[] args)
{
int length=10; //length of password
System.out.println(pass(length));
}

static char[] pass(int len)


{
System.out.println("generating password :");
System.out.print("your password is :");

String customer_name="customerCUSTOMER"; //customer name


int age=22; //Age
String id="100001"; //id

String values=customer_name + age + id;

Random rndm_method = new Random();

char[] password = new char[len];

for(int i=0;i<len;i++)
{
password[i] =
values.charAt(rndm_method.nextInt(values.length()));

}
return password;
}
}

OUTPUT:

You might also like