Java Program:

- To print sum of rows|columns|diagonals of an N x N magic matrix

Example:

User Input: 3

Output: 15

import java.util.Scanner;
public class SumOfMagicMatrix {
  public static void main(String []args) {
    int n;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter N of N X N magic matrix(must be odd number) :");
    n = userInput.nextInt();

    System.out.print("Sum of rows|columns|diagonals of "+n+" x "+n+" magic matrix : ");
    System.out.print((n*(n*n+1))/2);
  }
}

Output:

  Enter N of N X N magic matrix(must be odd number) : 5
  Sum of rows|columns|diagonals of 5 x 5 magic matrix : 65
Program
puzzle

Remember : Magic matrix are always odd value matrix

 like : 3x3,5x5,7x7,.....

So, you must first check it for an Odd value

(n*(n*n+1))/2 //Formula to calculate the sum

To check for odd value

n%2!=0
Concept

Coming Soon !

Quick
Tutorial

Quote

The best preparation for good work tomorrow is to do good work today.