Implement Transpose of A Given Matrix: 1. Solution

You might also like

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

1.

Implement transpose of a given matrix


Solution:-

package LearningJava;

import java.util.*;

public class tansposeMatrix

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();//limit of array

int [][] arr = new int[n][n];

for(int i =0;i<n;i++)

for(int j=0;j<n;j++)

arr[i][j]=sc.nextInt();

System.out.println();

for(int i=0;i<n;i++)

for(int j=0;j<n;j++)

System.out.print(arr[j][i]+" ");

System.out.println();

}
}

2. Implement multiplication of two Matrix


Solution:-
package LearningJava;

import java.util.*;

public class MultiplicationOfMatrix


{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.print("Enter rows for matrix: ");


int r = sc.nextInt();
System.out.print("Enter cloumns for matrix: ");
int c = sc.nextInt();
int [][] mul = new int[r][c];

//user input for 1st matrix

int [][] mat1 = new int [r][c];


System.out.print("Enter 1st matrix elements \n");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
mat1[i][j] = sc.nextInt();
}
}

//user input for 2nd matrix

int [][] mat2 = new int [r][c];


System.out.print("Enter 2nd matrix elements \n");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
mat2[i][j] = sc.nextInt();
}
}

//logic

for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
mul[i][j]=0;
for(int k=0;k<c;k++)
{
mul[i][j]+=mat1[i][k]*mat2[k][j];
}
}
}

//output display

for(int l=0;l<r;l++)
{
for(int m=0;m<c;m++)
{
System.out.print(mul[l][m]+" ");
}
System.out.println();
}

}
}

3. Implement a program to generate random password based on

customer name, age and id for banking applications.


Solution:-

package LearningJava;

import java.util.*;

public class RandomPassword

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

System.out.println("Enter Your Name: ");

String name = sc.nextLine(),r="";

System.out.println("Enter Your Age: ");

int age = sc.nextInt();

System.out.println("Enter Your DoB(dd/mm/yyyy): ");

int dob = sc.nextInt();

String t =""+name+age+dob;

for(int i=0;i<10;i++)

r+=t.charAt((int)(Math.random()*t.length()));

System.out.println("Your Password is: "+r);

}
}

You might also like