每天都努力的课堂随笔Day08
作者:互联网
Recursion
-
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(); test.test(); } public void test(){ 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) { System.out.println(f(5)); } public static int f(int n){ if( n== 1){ return 1; }else{ return n*f(n-1); } } }
Arrays
- Summary of Arrays
- Statement of creating Arrays
- Using of Arrays
- Multidimensional Array
- Class of Arrays
- Sparse Arrays
Definition
-
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 or 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.
-
获取数组长度
arrays.length
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 //3.给数组中元素赋值 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; System.out.println(nums[0]); //calculate all elements sum int sum = 0; for (int i = 0; i < nums.length; i++) { sum = sum + nums[i]; } System.out.println(sum); } }
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
-
标签:Day08,nums,int,could,array,method,课堂,随笔,public 来源: https://www.cnblogs.com/chenwenge/p/16700364.html