JAVA MATRIX & ARRAY OPERATIONS
Professional Developer Portfolio
Advanced Java Programming Tasks Collection
Prepared By: Student Developer
Subject: Java Programming
Category: Arrays & Matrix Operations
Document Type: Professional Code Documentation
Academic Session: 2026
A professionally formatted collection of Java programming tasks demonstrating array
manipulation, matrix operations, rotations, validations, replacements, and mathematical
computations.
\newpage
Table of Contents
1. Task 1 – Two-Dimensional Array Input & Output
2. Task 2 – Sum & Average of Array Elements
3. Task 3 – Matrix Rotation Program
4. Task 4 – Replace Negative Values with Zero
5. Task 5 – Swap First & Last Row
6. Task 6 – Matrix Addition Program
Task 1 – Two-Dimensional Array Input & Output
import java.util.Scanner;
public class Task1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
int row = input.nextInt();
1
, System.out.println("Enter the number of columns: ");
int col = input.nextInt();
int[][] array = new int[row][col];
fillArray(array);
printArray(array);
}
static void fillArray(int[][] array) {
Scanner input = new Scanner(System.in);
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array[i].length; ++j) {
System.out.println(
"Enter the value for index " + (1 + j) +
" of row at index " + (1 + i) + ": "
);
array[i][j] = input.nextInt();
}
}
}
static void printArray(int[][] array) {
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array[i].length; ++j) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}
Task 2 – Sum & Average of Array Elements
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
2
Professional Developer Portfolio
Advanced Java Programming Tasks Collection
Prepared By: Student Developer
Subject: Java Programming
Category: Arrays & Matrix Operations
Document Type: Professional Code Documentation
Academic Session: 2026
A professionally formatted collection of Java programming tasks demonstrating array
manipulation, matrix operations, rotations, validations, replacements, and mathematical
computations.
\newpage
Table of Contents
1. Task 1 – Two-Dimensional Array Input & Output
2. Task 2 – Sum & Average of Array Elements
3. Task 3 – Matrix Rotation Program
4. Task 4 – Replace Negative Values with Zero
5. Task 5 – Swap First & Last Row
6. Task 6 – Matrix Addition Program
Task 1 – Two-Dimensional Array Input & Output
import java.util.Scanner;
public class Task1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
int row = input.nextInt();
1
, System.out.println("Enter the number of columns: ");
int col = input.nextInt();
int[][] array = new int[row][col];
fillArray(array);
printArray(array);
}
static void fillArray(int[][] array) {
Scanner input = new Scanner(System.in);
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array[i].length; ++j) {
System.out.println(
"Enter the value for index " + (1 + j) +
" of row at index " + (1 + i) + ": "
);
array[i][j] = input.nextInt();
}
}
}
static void printArray(int[][] array) {
for (int i = 0; i < array.length; ++i) {
for (int j = 0; j < array[i].length; ++j) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}
Task 2 – Sum & Average of Array Elements
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
2