Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create mirror image an array. #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions ArrayImageCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.Scanner;

public class ArrayImageCreator {
public static void main(String[] args) {
processImageArray();
}

static void processImageArray() {

Scanner reader = new Scanner(System.in);
System.out.println("Enter the number of rows");

int rowCount = reader.nextInt();
System.out.println("Enter number of columns");

int columnCount = reader.nextInt();

int[][] array = new int[rowCount][columnCount];
System.out.println("Starting input of array elements...\n");

for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < columnCount; j++) {
System.out.println("Enter element of row " + (i + 1) +
", column " + (j + 1));

array[i][j] = reader.nextInt();
}
}

reader.close();
System.out.println("Entered array is : ");

displayArray(array);

int[][] mirrorImage = new int[rowCount][columnCount];

for (int row = 0; row < rowCount; row++) {

int imageColumn = 0;

for (int column = columnCount - 1; column >= 0; column--) {

int element = array[row][column];

mirrorImage[row][imageColumn] = element;

imageColumn++;
}
}
System.out.println("Mirror image of array is : ");

displayArray(mirrorImage);

}

static void displayArray(int[][] array) {
for (int i = 0; i < array.length; i++) {
int[] row = array[i];
for (int j = 0; j < row.length; j++) {
int element = array[i][j];
System.out.print(element + " ");
}
System.out.println();
}
}
}