Java instance: 6x6 gongge calculation of the sum of two diagonal numbers (code)

Source: Internet
Author: User
This article brings you the content is about Java instance: 6x6 Gongge Two diagonal numbers of the sum of the calculation (code), there is a certain reference value, the need for a friend can refer to, I hope to help you.


Calculates the sum of two diagonal numbers and writes a simpler code

public class Training {public static void main (string[] args) {        int [] [] scores = new Int[6][6];int num = 0;int sum1 = 0; int sum2 = 0;for (int i = 0; i < 6; i++) {for (int j = 0; J < 6; J + +) {Scores[i][j]=++num;}} for (int i = 0; i< 6;i++) {sum1 + = scores[i][i];sum2 + = Scores[i][6-i-1];} System.out.println (SUM1); System.out.println (sum2);    }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.