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

Implement Transpose of A Given Matrix Solution

The document contains code snippets for three matrix operations: 1) Transposing a matrix, 2) Multiplying two matrices, and 3) Generating a random password based on user inputs.
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)
107 views4 pages

Implement Transpose of A Given Matrix Solution

The document contains code snippets for three matrix operations: 1) Transposing a matrix, 2) Multiplying two matrices, and 3) Generating a random password based on user inputs.
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

1) Implement transpose of a given matrix

SOLUTION:

public class TRANSPOSE {

public static void main(String[] args) {


int[][] original= {{1,2,3},{4,5,6},{7,8,9}};
int[][] transpose= new int[3][3];
System.out.println("Original matrix");
for (int i=0;i<original.length;i++)
{ for(int p=0;p<original[i].length;p++)
{
System.out.println(original[i][p]);
}

System.out.println("Transpose of a matrix");
for (int i=0;i<original.length;i++)
{ for(int p=0;p<original[i].length;p++)
{
transpose[i][p]=original[p][i];
System.out.println(transpose[i][p]);
}
}
}
}
2. Implement multiplication of two Matrix
SOLUTION:

public class MATRIXMUL {

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<A.length;i++) {
for(int j=0;j<A[i].length;j++)
{
for(int k=0;k<B[i].length;k++)
{
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int n=0;n<C.length;n++) {
for(int h=0;h<C[n].length;h++)
{
System.out.println(C[n][h]);
}
}

}
}
3. Implement a program to generate random password based on
customer name, age and id for banking applications
SOLUTION:
import java.util.Scanner;
public class PASSWORDGENERATION {

public static void main(String[] args) {


Scanner obj=new Scanner(System.in);
System.out.println("Enter the name");
String name=obj.nextLine();
System.out.println("Enter age");
int age=obj.nextInt();
System.out.println("Enter id");
int id=obj.nextInt();
String
candidateChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!
@#$%^&*()";
String finalstring=" ";
for(int i=0;i<8;i++)
{
finalstring+=candidateChars.charAt((int)(Math.random()*candidateChars.length()));

}
System.out.println("Name " +name);
System.out.println("Age "+age);
System.out.println("id "+id);
System.out.println("Password is" +finalstring);

You might also like