[go: up one dir, main page]

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

Package Import Public Class Public Static Void: // Auto-Generated Method Stub

The document contains code for three Java programs: 1) A program to transpose a matrix by reading input from the user and printing the original and transposed matrices. 2) A program to multiply two matrices by taking input for the matrices and printing the product. 3) A program to generate a random password of a given length for a user by combining uppercase letters, lowercase letters, numbers and symbols.

Uploaded by

maitrayee kar
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)
56 views5 pages

Package Import Public Class Public Static Void: // Auto-Generated Method Stub

The document contains code for three Java programs: 1) A program to transpose a matrix by reading input from the user and printing the original and transposed matrices. 2) A program to multiply two matrices by taking input for the matrices and printing the product. 3) A program to generate a random password of a given length for a user by combining uppercase letters, lowercase letters, numbers and symbols.

Uploaded by

maitrayee kar
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/ 5

______________ASSIGNMENT 3______________________________

CODE:

package Ritam;
import java.util.Scanner;

public class TransposeMatrix {

public static void main(String[] args) {


// TODO Auto-generated method stub

int i, j;
System.out.println("Enter total rows and columns: ");
Scanner s = new Scanner(System.in);
int row = s.nextInt();
int column = s.nextInt();
int array[][] = new int[row][column];
System.out.println("Enter matrix:");
for(i = 0; i < row; i++)
{
for(j = 0; j < column; j++)
{
array[i][j] = s.nextInt();
System.out.print(" ");
}
}
System.out.println("The above matrix before Transpose is
");
for(i = 0; i < row; i++)
{
for(j = 0; j < column; j++)
{
System.out.print(array[i][j]+" ");
}
System.out.println(" ");
}
System.out.println("The above matrix after Transpose is
");
for(i = 0; i < column; i++)
{
for(j = 0; j < row; j++)
{
System.out.print(array[j][i]+" ");
}
System.out.println(" ");
}
}
}

OUTPUT:

Enter total rows and columns:


3 4
Enter matrix:
8 9 0
3 4 5 6
6 7 8
980
78
The above matrix before Transpose is
8 9 0 3
4 5 6 6
7 8 980 78
The above matrix after Transpose is
8 4 7
9 5 8
0 6 980
3 6 78

CODE:

package Ritam;
import java.util.Scanner;
public class MatrixMultiplication {

public static void main(String[] args) {


// TODO Auto-generated method stub

int m, n, p, q, sum = 0, c, d, k;

Scanner in = new Scanner(System.in);


System.out.println("Enter the number of rows and columns
of first matrix");
m = in.nextInt();
n = in.nextInt();

int first[][] = new int[m][n];

System.out.println("Enter elements of first matrix");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
first[c][d] = in.nextInt();

System.out.println("Enter the number of rows and columns


of second matrix");
p = in.nextInt();
q = in.nextInt();

if (n != p)
System.out.println("The matrices can't be multiplied
with each other.");
else
{
int second[][] = new int[p][q];
int multiply[][] = new int[m][q];

System.out.println("Enter elements of second


matrix");

for (c = 0; c < p; c++)


for (d = 0; d < q; d++)
second[c][d] = in.nextInt();

for (c = 0; c < m; c++)


{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k]*second[k][d];
}

multiply[c][d] = sum;
sum = 0;
}
}

System.out.println("Product of the matrices:");

for (c = 0; c < m; c++)


{
for (d = 0; d < q; d++)
System.out.print(multiply[c][d]+"\t");

System.out.print("\n");
}
}
}
}
OUTPUT:
Enter the number of rows and columns of first matrix
3 3
Enter elements of first matrix
1 2 3
4 5 6
7 8 9
Enter the number of rows and columns of second matrix
3 3
Enter elements of second matrix
9 8 7
6 5 4
3 2 1
Product of the matrices:
30 24 18
84 69 54
138 114 90

CODE:

package Ritam;
import java.util.*;
public class PassWordGenerator {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter the customer name: ");
String name=sc.nextLine();
System.out.println("enter the Id:");
int id=sc.nextInt();
System.out.println("Enter the length of the password: ");
int length=sc.nextInt();

System.out.println(maitrayee_Password(length));

}
static char[] maitrayee_Password(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");

String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


String Small_chars = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%^&*_=+-/.?<>)";

String values = Capital_chars + Small_chars +


numbers + symbols;
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:

Enter the customer name:


Maitrayee
enter the Id:
9087
Enter the length of the password:
6
Generating password using random() :
Your new password is : bBR42h

You might also like