Skip to content

Commit 65f8f3e

Browse files
committed
28/9/2024
1 parent 865b28e commit 65f8f3e

File tree

102 files changed

+3331
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3331
-0
lines changed

DDA/DoublyMarkov.class

2.77 KB
Binary file not shown.

DDA/DoublyMarkov.ctxt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#BlueJ class context
2+
comment0.target=DoublyMarkov
3+
comment1.params=
4+
comment1.target=void\ input()
5+
comment2.params=
6+
comment2.target=boolean\ element()
7+
comment3.params=
8+
comment3.target=boolean\ sumrow()
9+
comment4.params=
10+
comment4.target=boolean\ sumcolumn()
11+
comment5.params=
12+
comment5.target=void\ display()
13+
comment6.params=
14+
comment6.target=void\ main()
15+
numComments=7

DDA/DoublyMarkov.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package DDA;
2+
3+
import java.util.Scanner;
4+
5+
public class DoublyMarkov
6+
{
7+
double m[][];
8+
int n;
9+
10+
public void input()
11+
{
12+
Scanner as = new Scanner(System.in);
13+
System.out.println("Enter size of array: ");
14+
int size = as.nextInt();
15+
n = size;
16+
if (n >= 3 && n <= 9)
17+
{
18+
m = new double[n][n];
19+
System.out.println("Enter " + (n * n) + " Elements: ");
20+
for (int i = 0; i < n; i++)
21+
{
22+
for (int j = 0; j < n; j++)
23+
m[i][j] = as.nextDouble();
24+
}
25+
}
26+
else
27+
System.out.println("Invalid Input");
28+
}
29+
30+
public boolean element()
31+
{
32+
int f = 0;
33+
for (int i = 0; i < n; i++)
34+
{
35+
int t = 0;
36+
for (int j = 0; j < n; j++)
37+
{
38+
if (m[i][j] < 0)
39+
{
40+
t = 1;
41+
break;
42+
}
43+
}
44+
if (t == 1)
45+
{
46+
f = 1;
47+
break;
48+
}
49+
}
50+
if (f == 0)
51+
return true;
52+
else
53+
return false;
54+
}
55+
56+
public boolean sumrow()
57+
{
58+
int t = 0;
59+
for (int i = 0; i < n; i++)
60+
{
61+
double s = 0;
62+
for (int j = 0; j < n; j++)
63+
{
64+
s = s + m[i][j];
65+
}
66+
if (s != 1)
67+
{
68+
t = 1;
69+
break;
70+
}
71+
}
72+
if (t == 0)
73+
return true;
74+
else
75+
return false;
76+
}
77+
78+
public boolean sumcolumn()
79+
{
80+
int t = 0;
81+
for (int i = 0; i < n; i++)
82+
{
83+
double s = 0;
84+
for (int j = 0; j < n; j++)
85+
{
86+
s = s + m[j][i];
87+
}
88+
if (s != 1)
89+
{
90+
t = 1;
91+
break;
92+
}
93+
}
94+
if (t == 0)
95+
return true;
96+
else
97+
return false;
98+
}
99+
100+
public void display()
101+
{
102+
System.out.println("Matrix: ");
103+
for (int i = 0; i < n; i++)
104+
{
105+
for (int j = 0; j < n; j++)
106+
System.out.print(m[i][j] + " ");
107+
System.out.println();
108+
}
109+
if (element() && sumrow() && sumcolumn())
110+
{
111+
System.out.println("Doubly Markov Matrix");
112+
}
113+
else
114+
{
115+
System.out.println("Not a Doubly Markov Matrix");
116+
}
117+
}
118+
119+
public static void main()
120+
{
121+
DoublyMarkov obj = new DoublyMarkov();
122+
obj.input();
123+
obj.display();
124+
}
125+
}

DDA/Matrix.class

2.68 KB
Binary file not shown.

DDA/Matrix.ctxt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#BlueJ class context
2+
comment0.target=Matrix
3+
comment1.params=args
4+
comment1.target=void\ main(java.lang.String[])
5+
comment2.params=matrix
6+
comment2.target=void\ displayMatrix(int[][])
7+
comment3.params=matrix
8+
comment3.target=int[][]\ rotateMatrixClockwise(int[][])
9+
comment4.params=matrix
10+
comment4.target=int\ calculateOddSum(int[][])
11+
numComments=5

DDA/Matrix.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package DDA;
2+
3+
import java.util.Scanner;
4+
5+
public class Matrix {
6+
public static void main(String[] args) {
7+
Scanner scanner = new Scanner(System.in);
8+
9+
System.out.print("Enter the number of rows (m): ");
10+
int m = scanner.nextInt();
11+
System.out.print("Enter the number of columns (n): ");
12+
int n = scanner.nextInt();
13+
14+
if (m <= 2 || n <= 2 || m >= 10 || n >= 10) {
15+
System.out.println("Invalid input. Rows and columns must be between 3 and 9.");
16+
return;
17+
}
18+
int[][] matrix = new int[m][n];
19+
System.out.println("Enter matrix elements:");
20+
for (int i = 0; i < m; i++) {
21+
for (int j = 0; j < n; j++) {
22+
matrix[i][j] = scanner.nextInt();
23+
}
24+
}
25+
System.out.println("Original matrix:");
26+
displayMatrix(matrix);
27+
28+
int[][] rotatedMatrix = rotateMatrixClockwise(matrix);
29+
System.out.println("Rotated matrix (270 Degree Anti-clockwise):");
30+
displayMatrix(rotatedMatrix);
31+
32+
int oddSum = calculateOddSum(matrix);
33+
System.out.println("Sum of odd elements: " + oddSum);
34+
}
35+
public static void displayMatrix(int[][] matrix) {
36+
for (int[] row : matrix) {
37+
for (int element : row) {
38+
System.out.print(element + " ");
39+
}
40+
System.out.println();
41+
}
42+
}
43+
public static int[][] rotateMatrixClockwise(int[][] matrix) {
44+
int rows = matrix.length;
45+
int cols = matrix[0].length;
46+
int[][] rotated = new int[cols][rows];
47+
48+
for (int i = 0; i < rows; i++) {
49+
for (int j = 0; j < cols; j++) {
50+
rotated[j][rows - 1 - i] = matrix[i][j];
51+
}
52+
}
53+
return rotated;
54+
}
55+
public static int calculateOddSum(int[][] matrix) {
56+
int sum = 0;
57+
for (int[] row : matrix) {
58+
for (int element : row) {
59+
if (element % 2 != 0) {
60+
sum += element;
61+
}
62+
}
63+
}
64+
return sum;
65+
}
66+
}
67+

DDA/MirrorInage.class

1.97 KB
Binary file not shown.

DDA/MirrorInage.ctxt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#BlueJ class context
2+
comment0.target=MirrorInage
3+
comment1.params=arr
4+
comment1.target=void\ Display(int[][])
5+
comment2.params=arr
6+
comment2.target=int[][]\ arrMirrorer(int[][])
7+
comment3.params=args
8+
comment3.target=void\ main(java.lang.String[])
9+
numComments=4

DDA/MirrorInage.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package DDA;
2+
3+
import java.util.Scanner;
4+
5+
public class MirrorInage {
6+
static void Display(int[][] arr) {
7+
for (int i = 0; i < arr.length; i++) {
8+
for (int j = 0; j < arr[i].length; j++) {
9+
System.out.print(arr[i][j] + "\t");
10+
}
11+
System.out.println();
12+
}
13+
}
14+
static int[][] arrMirrorer(int[][] arr) {
15+
int n = arr.length;
16+
int[][] ModdedArray = new int[n][n];
17+
18+
for (int i = 0; i < n; i++) {
19+
for (int j = 0; j < n; j++) {
20+
ModdedArray[i][j] = arr[i][n - j - 1];
21+
}
22+
}
23+
return ModdedArray;
24+
}
25+
public static void main(String[] args) {
26+
Scanner scanner = new Scanner(System.in);
27+
28+
System.out.print("Enter the size of the Array: ");
29+
int n = scanner.nextInt();
30+
int[][] arr = new int[n][n];
31+
32+
System.out.println("Enter the elements of the arr:");
33+
for (int i = 0; i < n; i++) {
34+
for (int j = 0; j < n; j++) {
35+
arr[i][j] = scanner.nextInt();
36+
}
37+
}
38+
System.out.println("Original arr:");
39+
Display(arr);
40+
41+
int[][] ModdedArray = arrMirrorer(arr);
42+
System.out.println("Modified arr:");
43+
Display(ModdedArray);
44+
}
45+
}
46+

DDA/Rotate.class

1.95 KB
Binary file not shown.

0 commit comments

Comments
 (0)