0% found this document useful (0 votes)
111 views5 pages

Implement Transpose of A Given Matrix: Assignment-3

The document contains code for 3 programming assignments: 1) Implementing the transpose of a matrix by swapping row and column values. 2) Implementing the multiplication of two matrices by calculating the dot product of each row of the first and column of the second. 3) Generating a random password for banking applications by combining characters from the user's name, ID number, and other values.

Uploaded by

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

Implement Transpose of A Given Matrix: Assignment-3

The document contains code for 3 programming assignments: 1) Implementing the transpose of a matrix by swapping row and column values. 2) Implementing the multiplication of two matrices by calculating the dot product of each row of the first and column of the second. 3) Generating a random password for banking applications by combining characters from the user's name, ID number, and other values.

Uploaded by

Manaswi Minnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT-3

1. Implement transpose of a given matrix


CODE:

package Project1;

import java.util.Scanner;

public class MatrixTranspose {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[][] mat=new int[n][n];
System.out.println("enter the rows and col: ");
int a,b;
a=sc.nextInt();
b=sc.nextInt();
System.out.println("enter matrix elements:");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
mat[i][j]=sc.nextInt();
}
}
int[][] transposemat=new int[n][n];
for(int i=0;i<b;i++)
{
for(int j=0;j<a;j++)
{
transposemat[j][i]=mat[i][j];
}
}
System.out.println("transpose matrix:");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
System.out.printf(transposemat[i][j]+"\t");
}
}System.out.println("\n");

}
OUTPUT:

10
enter the rows and col:
3 3
enter matrix elements:
3 4 5
3 4 5
5 6 7
transpose matrix:
3 3 5
4 4 6
5 5 7

2. Implement multiplication of two Matrix

CODE:
package Project1;

import java.util.Scanner;

public class MultipleMat {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("enter n value");
int n=sc.nextInt();
int sum=0;
int[][] a=new int[n][n];
int[][] b=new int[n][n];
int[][] c=new int[n][n];
System.out.println("enter first matrix elements ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("enter second matrix elements ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
b[i][j]=sc.nextInt();
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
sum=0;
}
}
System.out.println("Resultant matrix:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println("\n");
}

OUTPUT:

enter n value
3
enter first matrix elements
1 2 3
4 5 6
7 8 9
enter second matrix elements
1 1 1
1 1 1
1 1 1
Resultant matrix:
6 6 6

15 15 15

24 24 24

3. Implement a program to generate random password based on


customer name, age and id for banking applications

CODE:

package Project1;

import java.util.Random;
import java.util.Scanner;

public class Tester{


public static void main(String[] args) {
System.out.println(generatePassword(8));
}

private static char[] generatePassword(int length) {


Scanner sc=new Scanner(System.in);
System.out.println("enter your name ");
String name1 = sc.nextLine();

String name = name1.toUpperCase();


String lowerCaseLetters = name1.toLowerCase();

String specialCharacters = "!@#$";

System.out.println("enter number");

double num=sc.nextDouble();

System.out.println("enter id:");

double id=sc.nextDouble();

double number=num+id;

String numbers = Double.toString(number);

String combinedChars = name + lowerCaseLetters +


specialCharacters + numbers;

Random random = new Random();

char[] password = new char[length];

password[0] =
lowerCaseLetters.charAt(random.nextInt(lowerCaseLetters.length()));

password[1] = name.charAt(random.nextInt(name.length()));
password[2] =
specialCharacters.charAt(random.nextInt(specialCharacters.length()))
;

password[3] =
numbers.charAt(random.nextInt(numbers.length()));

for(int i = 4; i< length ; i++)


{
password[i] =
combinedChars.charAt(random.nextInt(combinedChars.length()));
}
return password;
}
}

OUTPUT:

enter your name


sheetal
enter number
8547965212
enter id:
52648

aE@1ET$9

You might also like