Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! The fourth day!

Source: Internet
Author: User

Day04
    1. In the array, the data name. length is used to get the number of elements in this array.

Exercise 1: Write a function that prints the maximum or minimum value in an array.

Exercise 2: Write a function to sort an array (using bubble sort and select sort).

    1. Bubble sorting and selection sorting are not seen in real-world applications, because the values of the arrays are stored in heap memory, and both sorts are frequent displacement locations, so more resources are consumed in heap memory. Especially if there are more elements in the array. In actual development, we typically use the function sort that is already encapsulated in the array package. That is, Array.Sort (the array name) can be sorted quickly.

Exercise 3: Define a function whose function is to find the desired element in the array and output its subscript.

    1. Binary lookup: Can only be applied to an ordered array, that is, using three variables, one for the first subscript, one for the middle value, one for the last subscript, the middle value and the value you want to compare, if less than the value to find, then the first value of the lower value moved to the position of subscript +1 of the current median, and so on Returns 1 when the value to be found is not found, that is, when the first subscript is greater than the last subscript.
    2. In the program, a decimal number is converted to binary, and we can get the number modulo 2, and store it. Then divide the number of times by 2 and determine whether it is greater than 0. The binary representation of this number is obtained by dividing the number by 2 by 0. (There is also a well-defined conversion method in Java, i.e. integer.tobinarystring ())
    3. A two-dimensional array, which can be called an array in an array, is an understanding of the data that we have stored in the array, or an array. Initialize to int[][] arr = new Int[3][4]. As you can see, a two-dimensional array is defined, with three one-dimensional arrays in two-dimensional arrays, and four elements in each one-dimensional array.

int[][] arr = new int[3][]; this line of code means that a one-dimensional array of three unknown lengths is positioned in a two-dimensional array, and the three one-dimensional arrays are not defined, so the default address value is null. If the three array is again a single array, then the memory will be divided into a space, this address value will be assigned to a two-dimensional array of one-dimensional array, that is, when you define, memory is not in the memory of the two-dimensional array has been allocated to open up, but re-opened another piece of memory

int[][] arr = new INT[][3]; this definition is wrong.

    1. Exercise: Int[]x,y[];x and y are several dimensional arrays

Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! The fourth day!

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.