精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细


2022-09-16 16:31:23  阅读:280  来源: 互联网

标签:Day08 nums int could array method 课堂 随笔 public


  • Method A call method B, it is easy to grasp!

  • Recursion: Method A call method A, that is method A call itself.

  • Using recursion could solve some complex matters, it usually swap a big and complex problem to a small scale problem, recursion strategy need less coding to state the progress of solving problem, it could reduce repetitive calculation. The abilities of recursion is to use finite statements to define infinite collection of objects.

  • Recursion structure including two parts as following:

  • Head of recursion: time not to method-self, without head it would lost in endless loop.

  • Body of recursion: time ought to call method-self.

  • package com.example.demo08.mehod;
    public class Demo05 {
        public static void main(String[] args) {
            Demo05 test = new Demo05();
        public void test(){
  • package com.example.demo08.mehod;
    public class Demo06 {
        //2! 2*1
        //3! 3*2*1
        //5! 5*4*3*2*1
        public static void main(String[] args) {
        public static int f(int n){
            if( n== 1){
                return 1;
                return n*f(n-1);


  • Summary of Arrays
  • Statement of creating Arrays
  • Using of Arrays
  • Multidimensional Array
  • Class of Arrays
  • Sparse Arrays


  • An array is an ordered collection of data of the same type.

  • An array describes a number of data of the same type, arranged and combined in a certain order.

  • In an array, each piece of data is called an array element, and each array element can be accessed by a subscript

    Array Statement creation
    • You must first declare an array variable before you can use an array in your program. Here is the syntax for declaring array variables:(首先必须声明数组变量,才能在程序中使用数组。下面是声明数组变量的语法:)

      dataType[] arrayRefVar;//Perefered Method
      dataType[] aarayRefVar;//Comparing with the formmer, both of them have the same fuction, but it is not the perferred method.
    • The Java language uses the new operator to create arrays with the following syntax:

      dataType[] arrayRefVar = new dataType[arraySize];
    • The elements of an array are accessed by an index, which starts at 0.

    • 获取数组长度

      package com.example.demo08.mehod;
      public class ArrayDemo01 {
          //变量的类型 变量的名字  =  变量的值
          // 数组类型 
          public static void main(String[] args) {
               int[] nums;//1. define
               nums = new int[10];//create an array, we could store 10 int type numbers in this array
               nums[0] = 1;
               nums[1] = 2;
               nums[2] = 3;
               nums[3] = 4;
               nums[4] = 5;
               nums[5] = 6;
               nums[6] = 7;
               nums[7] = 8;
               nums[8] = 9;
               nums[9] = 10;
              //calculate all elements sum
              int sum = 0;
              for (int i = 0; i < nums.length; i++) {
                  sum = sum + nums[i]; 

      Three kinds of initialization & Memory analysis

      • Java Memory analysis

        • heap: it could store new objects and arrays

          ​ : and it could be shared by all threads, would not store others objects references

      • stack: store basic variable types

    ​ :referred objects variables

     - Method Area: it could be shared by all threads
     : it includes all the class and static variables

来源: https://www.cnblogs.com/chenwenge/p/16700364.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。


Copyright (C)ICode9.com, All Rights Reserved.