Recap - Multi-dimensional
Part of the Logic & Flow section of Coddy's C# journey — lesson 7 of 66.
Challenge
MediumCreate a method called processMatrix that:
- Takes a jagged array of integers (
int[][] matrix) as a parameter - Returns a new jagged array where:
- Each element is replaced with the sum of its adjacent elements (up, down, left, right)
- Elements at the edges only count the existing adjacent elements
- The original matrix should not be modified
For example, given the matrix:
[2, 3, 4]
[5, 6, 7]
[8, 9, 10]The result should be:
[8, 12, 10]
[16, 24, 20]
[14, 24, 16]For instance, the value 6 in the middle becomes 24 because its adjacent values are 3, 9, 5, and 7, and 3+9+5+7=24.
Try it yourself
public class ProcessMatrix
{
public static int[][] processMatrix(int[][] matrix)
{
// Write your code here
}
}All lessons in Logic & Flow
1Multi-dimensional Arrays
2D Arrays BasicsDeclaring and Initializing 2DAccessing 2D Array ElementsNested Loops with 2D ArraysJagged ArraysCommon Matrix OperationsRecap - Multi-dimensional4Flow Control Techniques
Early ReturnsGuard ClausesJump Statements (goto)Break and ContinueFlatten Nested Conditionals7Logical Operators Advanced
Short-Circuit EvaluationConditional Logical OperatorsOperator PrecedenceRecap - Advanced Operators2Advanced Decision Making
Multiple ConditionsComplex Boolean LogicIf vs. Switch ComparisonNested Switch StatementsRecap - Advanced Decisions5Exception Handling
Try-Catch BasicsException TypesMultiple Catch BlocksWorking with FilesFinally BlockUsing vs. Try-FinallyCustom ExceptionsRecap - Error Handling3Loop Enhancements
Loop PerformanceIterating ComplexEach Loop TypeRefactoring LoopsRecap - Optimized Loops6Null Handling
Null Reference BasicsNullable Value TypesNull Checking PatternsDefensive ProgrammingRecap - Null Safety