How to find the Sum of diagonal elements of a 3-3 Matrix by Java
This article mainly shows you "Java how to find the sum of diagonal elements of a 3x3 matrix", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Java how to find a sum of diagonal elements of a 30003 matrix" this article.
Find the sum of diagonal elements of a 3-3 matrix
This is a matrix programming implementation problem. Matrices in Java are generally implemented through two-dimensional arrays.
The specific code is as follows:
Import java.util.Random;/** * find the sum of the diagonal elements of a 3'3 matrix * * @ author ChenZX * * / public class Test04 {public static void main (String [] args) {int sum = 0; / / and int [] [] arr = new int [3] [3]; Random r = new Random (); for (int iPisti)