-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
865b28e
commit 65f8f3e
Showing
102 changed files
with
3,331 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#BlueJ class context | ||
comment0.target=DoublyMarkov | ||
comment1.params= | ||
comment1.target=void\ input() | ||
comment2.params= | ||
comment2.target=boolean\ element() | ||
comment3.params= | ||
comment3.target=boolean\ sumrow() | ||
comment4.params= | ||
comment4.target=boolean\ sumcolumn() | ||
comment5.params= | ||
comment5.target=void\ display() | ||
comment6.params= | ||
comment6.target=void\ main() | ||
numComments=7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package DDA; | ||
|
||
import java.util.Scanner; | ||
|
||
public class DoublyMarkov | ||
{ | ||
double m[][]; | ||
int n; | ||
|
||
public void input() | ||
{ | ||
Scanner as = new Scanner(System.in); | ||
System.out.println("Enter size of array: "); | ||
int size = as.nextInt(); | ||
n = size; | ||
if (n >= 3 && n <= 9) | ||
{ | ||
m = new double[n][n]; | ||
System.out.println("Enter " + (n * n) + " Elements: "); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
for (int j = 0; j < n; j++) | ||
m[i][j] = as.nextDouble(); | ||
} | ||
} | ||
else | ||
System.out.println("Invalid Input"); | ||
} | ||
|
||
public boolean element() | ||
{ | ||
int f = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
int t = 0; | ||
for (int j = 0; j < n; j++) | ||
{ | ||
if (m[i][j] < 0) | ||
{ | ||
t = 1; | ||
break; | ||
} | ||
} | ||
if (t == 1) | ||
{ | ||
f = 1; | ||
break; | ||
} | ||
} | ||
if (f == 0) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
public boolean sumrow() | ||
{ | ||
int t = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
double s = 0; | ||
for (int j = 0; j < n; j++) | ||
{ | ||
s = s + m[i][j]; | ||
} | ||
if (s != 1) | ||
{ | ||
t = 1; | ||
break; | ||
} | ||
} | ||
if (t == 0) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
public boolean sumcolumn() | ||
{ | ||
int t = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
double s = 0; | ||
for (int j = 0; j < n; j++) | ||
{ | ||
s = s + m[j][i]; | ||
} | ||
if (s != 1) | ||
{ | ||
t = 1; | ||
break; | ||
} | ||
} | ||
if (t == 0) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
public void display() | ||
{ | ||
System.out.println("Matrix: "); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
for (int j = 0; j < n; j++) | ||
System.out.print(m[i][j] + " "); | ||
System.out.println(); | ||
} | ||
if (element() && sumrow() && sumcolumn()) | ||
{ | ||
System.out.println("Doubly Markov Matrix"); | ||
} | ||
else | ||
{ | ||
System.out.println("Not a Doubly Markov Matrix"); | ||
} | ||
} | ||
|
||
public static void main() | ||
{ | ||
DoublyMarkov obj = new DoublyMarkov(); | ||
obj.input(); | ||
obj.display(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#BlueJ class context | ||
comment0.target=Matrix | ||
comment1.params=args | ||
comment1.target=void\ main(java.lang.String[]) | ||
comment2.params=matrix | ||
comment2.target=void\ displayMatrix(int[][]) | ||
comment3.params=matrix | ||
comment3.target=int[][]\ rotateMatrixClockwise(int[][]) | ||
comment4.params=matrix | ||
comment4.target=int\ calculateOddSum(int[][]) | ||
numComments=5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package DDA; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Matrix { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
System.out.print("Enter the number of rows (m): "); | ||
int m = scanner.nextInt(); | ||
System.out.print("Enter the number of columns (n): "); | ||
int n = scanner.nextInt(); | ||
|
||
if (m <= 2 || n <= 2 || m >= 10 || n >= 10) { | ||
System.out.println("Invalid input. Rows and columns must be between 3 and 9."); | ||
return; | ||
} | ||
int[][] matrix = new int[m][n]; | ||
System.out.println("Enter matrix elements:"); | ||
for (int i = 0; i < m; i++) { | ||
for (int j = 0; j < n; j++) { | ||
matrix[i][j] = scanner.nextInt(); | ||
} | ||
} | ||
System.out.println("Original matrix:"); | ||
displayMatrix(matrix); | ||
|
||
int[][] rotatedMatrix = rotateMatrixClockwise(matrix); | ||
System.out.println("Rotated matrix (270 Degree Anti-clockwise):"); | ||
displayMatrix(rotatedMatrix); | ||
|
||
int oddSum = calculateOddSum(matrix); | ||
System.out.println("Sum of odd elements: " + oddSum); | ||
} | ||
public static void displayMatrix(int[][] matrix) { | ||
for (int[] row : matrix) { | ||
for (int element : row) { | ||
System.out.print(element + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
public static int[][] rotateMatrixClockwise(int[][] matrix) { | ||
int rows = matrix.length; | ||
int cols = matrix[0].length; | ||
int[][] rotated = new int[cols][rows]; | ||
|
||
for (int i = 0; i < rows; i++) { | ||
for (int j = 0; j < cols; j++) { | ||
rotated[j][rows - 1 - i] = matrix[i][j]; | ||
} | ||
} | ||
return rotated; | ||
} | ||
public static int calculateOddSum(int[][] matrix) { | ||
int sum = 0; | ||
for (int[] row : matrix) { | ||
for (int element : row) { | ||
if (element % 2 != 0) { | ||
sum += element; | ||
} | ||
} | ||
} | ||
return sum; | ||
} | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#BlueJ class context | ||
comment0.target=MirrorInage | ||
comment1.params=arr | ||
comment1.target=void\ Display(int[][]) | ||
comment2.params=arr | ||
comment2.target=int[][]\ arrMirrorer(int[][]) | ||
comment3.params=args | ||
comment3.target=void\ main(java.lang.String[]) | ||
numComments=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package DDA; | ||
|
||
import java.util.Scanner; | ||
|
||
public class MirrorInage { | ||
static void Display(int[][] arr) { | ||
for (int i = 0; i < arr.length; i++) { | ||
for (int j = 0; j < arr[i].length; j++) { | ||
System.out.print(arr[i][j] + "\t"); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
static int[][] arrMirrorer(int[][] arr) { | ||
int n = arr.length; | ||
int[][] ModdedArray = new int[n][n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
ModdedArray[i][j] = arr[i][n - j - 1]; | ||
} | ||
} | ||
return ModdedArray; | ||
} | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
System.out.print("Enter the size of the Array: "); | ||
int n = scanner.nextInt(); | ||
int[][] arr = new int[n][n]; | ||
|
||
System.out.println("Enter the elements of the arr:"); | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
arr[i][j] = scanner.nextInt(); | ||
} | ||
} | ||
System.out.println("Original arr:"); | ||
Display(arr); | ||
|
||
int[][] ModdedArray = arrMirrorer(arr); | ||
System.out.println("Modified arr:"); | ||
Display(ModdedArray); | ||
} | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#BlueJ class context | ||
comment0.target=Rotate | ||
comment1.params=arr | ||
comment1.target=void\ Display(int[][]) | ||
comment2.params=arr | ||
comment2.target=int[][]\ arrMirrorer(int[][]) | ||
comment3.params=args | ||
comment3.target=void\ main(java.lang.String[]) | ||
numComments=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package DDA; | ||
/** | ||
# Question 5: | ||
Write a program in java to create a class “MirrorImage” and display the mirrored image of a 2D-array of m*n matrix. | ||
Example | ||
INPUT: n=4 | ||
Original Array: | ||
| 8 | 15 | 9 | 18 | | ||
| --- | --- | --- | --- | | ||
| 9 | 10 | 7 | 6 | | ||
| 10 | 8 | 11 | 13 | | ||
| 12 | 16 | 17 | 19 | | ||
Modified Array: | ||
| 18 | 9 | 15 | 8 | | ||
| --- | --- | --- | --- | | ||
| 6 | 7 | 10 | 9 | | ||
| 13 | 11 | 8 | 10 | | ||
| 19 | 17 | 16 | 12 | | ||
Algorithm | ||
1. Start. | ||
2. Import `java.util.Scanner`. | ||
3. Define `Display(int[][] arr)` to print a 2D array. | ||
4. Define `arrMirrorer(int[][] arr)` to create a mirror image of the array. | ||
5. Inside `Display`, loop through rows and columns of `arr`. | ||
6. Print each element followed by a tab and a new line after each row. | ||
7. Inside `arrMirrorer`, initialize `n` as the length of `arr`. | ||
8. Create a new 2D array `ModdedArray` of size `n x n`. | ||
9. Loop through rows and columns of `arr`. | ||
10. Assign `ModdedArray[i][j]` to `arr[i][n - j - 1]` to mirror horizontally. | ||
11. Return `ModdedArray`. | ||
12. Define `main` method. | ||
13. Create a `Scanner` object for input. | ||
14. Prompt and read integer `n` as the size of the array. | ||
15. Create a 2D array `arr` of size `n x n`. | ||
16. Prompt user to enter elements of the array. | ||
17. Loop through rows and columns to read and store input in `arr`. | ||
18. Print "Original array:" and call `Display(arr)`. | ||
19. Create `ModdedArray` by calling `arrMirrorer(arr)`. | ||
20. Print "Modified array:" and call `Display(ModdedArray)`. | ||
21. End | ||
*/ | ||
import java.util.Scanner; | ||
|
||
public class Rotate { | ||
static void Display(int[][] arr) { | ||
for (int i = 0; i < arr.length; i++) { | ||
for (int j = 0; j < arr[i].length; j++) { | ||
System.out.print(arr[i][j] + "\t"); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
static int[][] arrMirrorer(int[][] arr) { | ||
int n = arr.length; | ||
int[][] ModdedArray = new int[n][n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
ModdedArray[i][j] = arr[i][n - j - 1]; | ||
} | ||
} | ||
return ModdedArray; | ||
} | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
System.out.print("Enter the size of the Array: "); | ||
int n = scanner.nextInt(); | ||
int[][] arr = new int[n][n]; | ||
|
||
System.out.println("Enter the elenents of the arr:"); | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
arr[i][j] = scanner.nextInt(); | ||
} | ||
} | ||
System.out.println("Original arr:"); | ||
Display(arr); | ||
|
||
int[][] ModdedArray = arrMirrorer(arr); | ||
System.out.println("Modified arr:"); | ||
Display(ModdedArray); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#BlueJ class context | ||
comment0.target=Shift | ||
comment1.params=mm\ nn | ||
comment1.target=Shift(int,\ int) | ||
comment2.params= | ||
comment2.target=void\ input() | ||
comment3.params= | ||
comment3.target=void\ display() | ||
comment4.params=P | ||
comment4.target=void\ cyclic(Shift) | ||
comment5.params=args | ||
comment5.target=void\ main(java.lang.String[]) | ||
numComments=6 |
Oops, something went wrong.