Print interesting squares in Java

Source: Internet
Author: User

Printed Phalanx with Java

1 ImportJava.util.Scanner;2 3  Public classp1143 {4 5      Public Static voidMain (string[] args) {6         intI, J, n, k = 1;7         intA[][] =New int[100] [100];8Scanner reader =NewScanner (system.in);9n =reader.nextint ();Ten          for(i = 1; I <= N/2; i++) { One              forj = i; J <= N-i; j + +) { AA[I][J] =K; -k++; -                 //s the             } -              for(j = i; J. <=n-i; J + +) { -A[j][n+1-i] =K; -k++; +                 //y -             } +              for(j = n+1-i; J >= I+1; j--) { AA[N+1-I][J] =K; atk++; -                 //x -             } -              for(j = n+1-i; J >= I+1; j--) { -                  -A[j][i] =K; ink++; -                 //Z to             } +         } -         if(n% 2 = = 1) { thei = (n + 1)/2; *A[i][i] = n *N; $         }Panax Notoginseng          for(i = 1; I <= N; i++) { - System.out.println (); the              for(j = 1; J <= N; j + +) { +System.out.print ("" +a[i][j]); A             } the         } +     } -}

Print interesting squares in Java

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.