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

Source: Internet
Author: User

Bitwise operators :

>>> unsigned right-shift operators, the rules for unsigned right shifts are the same as those that move right, except that when they are filled, they are supplemented with zeros, regardless of whether the original is positive or negative.

Array:

ARR1=ARR2; At this point two array variables will point to the same array, that is, the array to which arr2 points, and if arr2 points to an array that changes, 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 sum of the rows and columns) */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.