0% found this document useful (0 votes)
190 views4 pages

Java Assignment 3

The document contains 3 Java programs: 1) A program to implement the transpose of a matrix by creating a second matrix and swapping the values of the original matrix. 2) A program to multiply two matrices by iterating through the rows and columns and multiplying the values. 3) A program to generate a random password of length 10 for banking applications by concatenating customer name, age, and id and selecting random characters from the string.

Uploaded by

vivek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views4 pages

Java Assignment 3

The document contains 3 Java programs: 1) A program to implement the transpose of a matrix by creating a second matrix and swapping the values of the original matrix. 2) A program to multiply two matrices by iterating through the rows and columns and multiplying the values. 3) A program to generate a random password of length 10 for banking applications by concatenating customer name, age, and id and selecting random characters from the string.

Uploaded by

vivek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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