I. The concept of arrays
An array can be regarded as a collection of multiple data types, which is a unified management of these data;
The variable of an array is a reference type, the array itself is an object, and each element in the array is equal to the member variable of that object;
The elements of an array can be any data type, including the underlying data type and the reference type;
Two. How arrays are declared
Data type + [] + array name = new + data type + [length of array];
Example: int[] arr = new ARR[6]; Can also be written as int arr[] = new ARR[6]; Generally used in the first form of the wording;
You can also define the contents of the array directly: int[] arr ={1,2,3,4,5,6} NOTE: You must use the New keyword when declaring an array;
Note: 1. To use the New keyword when declaring an array
2. The length of the array must be declared, and once defined, the length cannot be changed;
3. An array of reference types refers to the declaration of an array variable on the stack, the contents of which are present on the heap, and the variable points to that content;
Three. Traversal and initialization of arrays
1. Static initialization refers to defining the contents of the array directly, for example: int[] arr = {1,2,3,4};
2. Dynamic initialization refers to defining the contents of the array with traversal;
Four. public static void Main (string[] args)
Static no return value method for public means string type command parameter name
Main method refers to the main entrance of the program;
Use the args to make an arithmetic device:
public class Test3 {public static void main (string[] args) {if (args.length! = 3) {System.out.println ("Please enter the correct format! "); return;} int a = Integer.parseint (args[0]); int b = Integer.parseint (args[2]); String s = Args[1];switch (s) {case "+": System.out.println (A + b); Break;case "-": System.out.println (a); Break;case "/": System.out.println (A/b); Break;case "X": System.out.println (A * b); break;default:break;}}}
JAVA Fundamentals 3