Repository navigation
Expand file tree
/
Copy pathMatrixOperation.java
More file actions
88 lines (74 loc) · 1.75 KB
/
Copy pathMatrixOperation.java
File metadata and controls
88 lines (74 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package exersize;
import java.util.Scanner;
public class MatrixOperation {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("Enter Rows and Columns Value :");
int r=sc.nextInt();
int c=sc.nextInt();
int a[][]=new int[r][c];
System.out.println("Enter the Matrix Value :");
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Matrix is : \n");
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
/* Transpose Matrix */
//-------------------------//
// Watch deeply on the For loop//
System.out.println("TRanspose Matrix is : \n");
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
System.out.print(a[j][i]+" ");
}
System.out.println();
}
/* Center Element of an Array */
//-----------------------------//
double cen=(r*c)/2;
int s=(int) cen;
s=--s/2;
System.out.println();
System.out.println("Center Element of an Array :"+a[s][s]);
// Samllest value in an Array //
//----------------------------//
int sml=Integer.MAX_VALUE;
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
if(sml > a[i][j])
{
sml=a[i][j];
}
}
System.out.println();
}
System.out.println("Smallest element in an Array :"+sml);
//Sum of the all element in an Array//
//-----------------------------------//
int sum=0;
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
sum+=a[i][j];
}
System.out.println();
}
System.out.println("Smallest element in an Array :"+sum);
}
}