Defines a function that is dynamically extracting the maximum value of an element in int[].
public static void main (String[] args) { system.out.println (GetMax (new int [0])); int[] arr = new int[]{3,2,11,5}; system.out.println ("arr Maximum:" + getmax (arr)); } public static int getmax (Int[] arr) { int temp = Integer.MIN_VALUE; if (arr == null | | arr.length == 0) { system.out.print ("[Value error]"); return -1; } for (int i = 0;i < arr.length ;i++ ) { if (Temp < arr[i]) { temp = arr[i]; } } return temp; }
2. Defines a function that queries the location of the first occurrence of the specified element from the array.
public static void main (String[] args) { int[] arr = new int[]{1,2,3,4,5,6,0,10}; int index = searcharray (0, arr); } public static int searcharray (int Num,int[] arr) { if (arr == null) { system.out.println ("Arr value cannot be null"); return -1; } int index = -1; for (int i = 0;i < arr.length ;i++ ) { if (arr[i] == num) { index = i; system.out.println ("Number:" + num + ", existence Position:" + index); return i; } } System.out.println ("Can ' t search  Number: " + num); return -1 ; }
3. Define the function, complete the bubbling sort, and sink the large number.
public static void main (String[] args) { int[] arr = sort (New &NBSP;INT[]{-1,-22,0,-3,1,-33}); out (arr); } public static int[] sort (Int[] arr) { int temp = 0; for (int i = 0;i < arr.length ;i++ ) { for (int j = i + 1; j < arr.length ;j++ ) { if (Arr[i] > arr[j]) { temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } return arr; } public static void out (Int[] arr) { for (int i = 0;i < arr.length ;i++ ) { System.out.print (arr[i] + "\ T"); } system.out.println (); }
4. Binary find.
Class test {public static void main (String[] args) { int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; int a = 0,b = arr.length - 1,m = 0; int x = 2; while (a <= b) { m = (a + b) / 2; if (arr[m] == x) { system.out.println ("Index is:" + m) ; break; }else if (X < arr[m]) {&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; b = m - 1; }else { b = m + 1; } } }}
5. Defines a function that implements the transpose of the matrix. arr[i][j] = = arr[j][i];//the precondition is affirmative.
public static void main (String[] args) { int arr[][] = {{1,2,3},{4,5,6},{7,8,9}}; //out (arr); system.out.println ("------- -----------------"); arr = Trans (arr); out (arr); } public static int[][] trans (Int[][] arr) { for (int i = 0;i < arr.length - 1 ;i ++ ) { for (int j = i + 1; j < arr.length ;j ++ ) { int temp = arr[i][j]; arr[i][j] = arr[j][i]; arr[j][i] = temp; } } Return arr; } public static void out (int[][] arr) { for (int i = 0;i < arr.length;i++) { for (int j = 0;j < arr.length ;j ++ ) { system.out.print (arr[i][j] + "\ T"); } system.out.println ( ); } }
6. Traverse three-dimensional groups and output each layer of the three-dimensional array horizontally.
The answer to the teacher's question is still not clear ...
public static void main (String[] args) {int[][][] arr = { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } },{ { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } },{ { 19, 20, 21 }, { 22, 23, 24 }, { 25, 26, 27 } } };outhor (arr); } public static void outhor (Int[][][] arr) { for (int i = 0; i < arr.length ;i++ ) { for (int j = 0 ; j < arr.length; j++ ) &NBSP;&NBSP;&NBsp; { for (Int k = 0;k < arr[j][i]. length ;k++ ) { system.out.print (arr[j][i][k] + "\ T"); } system.out.print ("| " ); } system.out.println (); } }
7. Defines a class: Dog has the name Color Age cry ();
public static void main (String[] args) { dog d = new dog ("Yellow",; ) system.out.println ("Color:" + d.getcolor () + " age:" + d.getage ()); }}class Dog{ private String color; private int age; public Dog (string color,int age) { this.color = color; this.age = age; } public void setcolor (String color) { this.color = color; } public string getcolor () { return color; } public void setage (int age) { this.age = age; } public int getage () { return age; } public void cry () { system.out.println ("barking ~ ~ ~"); }
9. Describe the heap area, stack area, when overflow, how to solve.
For:
Heap Area: Stores objects and member variables.
Stack area: Stores local variables and method memory.
Overflow: An object that consumes large memory resources, or overflows when it is recursive.
Workaround:
JAVA-XMS;
10.oop
Face objects: As with the process, it is a programming method.
Class: The abstraction of an object.
Object: The instantiation of the class.
Instance: = Object
Member variable: An object's property variable.
member function: The method of the object.
Public: A common modifier that provides various types of calls.
Private: A proprietary modifier that improves security and is only allowed in this class. Its properties can be changed by the Set,get method. For encapsulation.
Constructor: Constructs an initialization object. no return value.
This: is a member variable of an object, used for method references and property references in a class.
Static: Statically, decorated member variable, member function. , a class can also reference static members, and static methods can only access static members.
"Big Data-Phase II" Java Foundation Third day job