Java Small Knowledge Point learning--------array and bit arithmetic small knowledge points

Source: Internet
Author: User

Bitwise operators :

>>> unsigned right-shift operators, rules for unsigned right shifts, and rules to move right also, just as the fill, no matter whether the original positive or negative are added with the zero.

Array:

ARR1=ARR2; At this point two array variables will point to the same array at the same time, that is, the array pointed to by ARR2, assuming arr2 points to the array changes, then arr1 and arr2 are changed.

Use Arrays.sort to sort (using a quick row)


Magic square Matrix : (direct to instance)

public class Magic {/** * uses multidimensional arrays to print an n-order magic square Matrix * The sum of the data elements on each column and diagonal of each row of the matrix * n takes an odd number (because of the diagonal and the row and column and equal) */public void mag (int n,int a[] [])//Pass order number and array {int i = 0, j, k;j = n/2;for (k = 1; k <= n * N; k++) {A[i][j] = K;//system.out.print ("a[" +i+ "[" +j+ "]=" +a[i][j]+ ""); if (k% n = = 0) {i = (i + 1)% n;} else {i = (i-1 + N)% N;j = (j + 1)% n;}}}  public static void Main (string[] args) {int n=3;int a[][] = new Int[n][n];new Magic (). Mag (n, a);//system.out.println (); for (int i = 0; i < n; i++) {for (int j = 0; J <n; J + +) {System.out.print (a[i][j]+ "\ t");} System.out.println ();}}}
Example Results:

8 1 6
3 5 7
4 9 2

Java Small Knowledge Point learning--------array and bit arithmetic small knowledge points

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.