inotgo.com


Tool version compatibility problem
An array is a Fixed length of , Contains Same type Of data Container
Correct

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning



8 branch 35 second
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



Step 1 : Declare an array   
Step 2 : Create an array   
Step 3 : Access array   
Step 4 : Array length   
Step 5 : practice - Minimum value of array   
Step 6 : answer - Minimum value of array   

int[] a; Declared an array variable .
[] Indicates that the variable is an array
int Indicates that each element in the array is an integer
a Is the variable name
But , Just this sentence Declare , Will not create an array

Sometimes it's written as int a[]; There is no difference , Is what kind of pleasing to the eye you see
public class HelloWorld { public static void main(String[] args) { // Declare an array int[] a; } }
public class HelloWorld {
	public static void main(String[] args) {
		//  Declare an array 
		int[] a;
	}
}
When creating an array , To indicate the length of the array .
new int[5]
Quote concepts :
If the variable represents an array , For example a, We put a be called quote
Different from the basic type
int c = 5; This is called c Assignment by 5
Declare a reference int[] a;
a = new int[5];
Give Way a This reference , Point to Array
 Create an array
public class HelloWorld { public static void main(String[] args) { // Declare a reference int[] a; // Create a length of 5 Array of , And use references a Point to the array a = new int[5]; int[] b = new int[5]; // At the same time , Point to an array } }
public class HelloWorld {
	public static void main(String[] args) {
		// Declare a reference 
		int[] a; 
		// Create a length of 5 Array of , And use references a Point to the array 
		a = new int[5];
		
		int[] b = new int[5]; // At the same time , Point to an array 
		
	}
}
Array subscript base 0
Subscript 0, Represents the first number in the array
 Access array
public class HelloWorld { public static void main(String[] args) { int[] a; a = new int[5]; a[0]= 1; // Subscript 0, Represents the first number in the array a[1]= 2; a[2]= 3; a[3]= 4; a[4]= 5; } }
public class HelloWorld {
	public static void main(String[] args) {
		int[] a; 
		a = new int[5];
		
		a[0]= 1;  // Subscript 0, Represents the first number in the array 
		a[1]= 2;
		a[2]= 3;
		a[3]= 4;
		a[4]= 5;
	}
}
.length attribute The length used to access an array
The array access subscript range is 0 To length -1
Once beyond this range , An array subscript out of bounds exception will be generated
 Array length
public class HelloWorld { public static void main(String[] args) { int[] a; a = new int[5]; System.out.println(a.length); // Print the length of the array a[4]=100; // Subscript 4, Essentially “ The first 5 individual ”, That is, the last a[5]=101; // Subscript 5, Essentially “ The first 6 individual ”, Out of range , An array subscript out of bounds exception is generated } }
public class HelloWorld {
	public static void main(String[] args) {
		int[] a; 
		a = new int[5];
		
		System.out.println(a.length); // Print the length of the array 
		
		a[4]=100; // Subscript 4, Essentially “ The first 5 individual ”, That is, the last  
		a[5]=101; // Subscript 5, Essentially “ The first 6 individual ”, Out of range  , An array subscript out of bounds exception is generated 
		
	}
}
Step 5 :

practice - Minimum value of array

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
First create a length of 5 Array of
Then give each bit of the array a random integer
Through for Cycle , Traverse the array , Find out the smallest value

0-100 of There are many ways to obtain random integers , Here is one of the reference methods :

(int) (Math.random() * 100)

Math.random() Will get a 0-1 Random floating point numbers between , Then multiply by 100, And forcibly convert to integer .
public class HelloWorld { public static void main(String[] args) { int[] a = new int[5]; a[0] = (int) (Math.random() * 100); a[1] = (int) (Math.random() * 100); a[2] = (int) (Math.random() * 100); a[3] = (int) (Math.random() * 100); a[4] = (int) (Math.random() * 100); System.out.println(" Each random number in the array is :"); for (int i = 0; i < a.length; i++) System.out.println(a[i]); System.out.println(" The purpose of this exercise is , Find the smallest value : "); } }
public class HelloWorld {
	public static void main(String[] args) {
		int[] a = new int[5];
		a[0] = (int) (Math.random() * 100);
		a[1] = (int) (Math.random() * 100);
		a[2] = (int) (Math.random() * 100);
		a[3] = (int) (Math.random() * 100);
		a[4] = (int) (Math.random() * 100);
		
		System.out.println(" Each random number in the array is :");
		for (int i = 0; i < a.length; i++) 
			System.out.println(a[i]);
		
		System.out.println(" The purpose of this exercise is , Find the smallest value : ");
	}
}
Step 6 :

answer - Minimum value of array

edit top fracture
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

3 branch 49 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


 answer - Minimum value of array
public class HelloWorld { public static void main(String[] args) { int[] a = new int[5]; a[0] = (int) (Math.random() * 100); a[1] = (int) (Math.random() * 100); a[2] = (int) (Math.random() * 100); a[3] = (int) (Math.random() * 100); a[4] = (int) (Math.random() * 100); System.out.println(" Each random number in the array is :"); for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); int min = 100; for (int i = 0; i < a.length; i++) { if( a[i] < min ) min = a[i]; } System.out.println(" The minimum value found is :" +min); } }


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-10-12 Writing method writing method
And far away




/**
 * @ClassName Arr
 * @Description  Array review , Find the smallest number in the array 
 * @Date 
 * @Author 
 * @Version 1.0
 */
public class Arr {

    /**
    * @Description:  Traverse and print the array 
    * @Param: [arr]
    * @return: void
    * @Author: 
    * @Date: 
    */
    public static void soutArr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.println("arr = " + arr[i]);
        }
    }

    /**
    * @Description:  Find the minimum number 
    * @Param: [arr]
    * @return: int
    * @Author: 
    * @Date:
    */
    public static int minArr(int[] arr) {
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < arr.length; i++) {
            if (min>arr[i]){
                min = arr[i];
            }
        }
        return min;
    }
    
    public static void main(String[] args) {
        int arr[] = new int[10];
        for (int i = 0 ; i < arr.length ; i++){
            arr[i] = (int)(Math.random()*100);
        }

        soutArr(arr);
        System.out.println("minArr(arr) = " + minArr(arr));

    }
}
 
               


3 One answer

Spicy chicken with vegetables
Answer time :2021-10-22
Pipi
Answer time :2021-10-16
es54
Answer time :2021-10-13



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-10-04 code
A feast




None
 Loading
 
               
 
               


4 One answer

Pipi
Answer time :2021-10-16
Kion11
Answer time :2021-10-12
Fengtai Wu Qilong
Answer time :2021-10-12
Makino li
Answer time :2021-10-08
package cn; public class Text5 { public static void main(String[] args) { // TODO Automatically generated method stub int[] a=new int[5]; int min; a[0]=(int)(Math.random()*100); a[1]=(int)(Math.random()*100); a[2]=(int)(Math.random()*100); a[3]=(int)(Math.random()*100); a[4]=(int)(Math.random()*100); System.out.println(" Each random number in the array is :"); for(int i=0;i<a.length;i++) { System.out.println(a[i]); min=a[0]; for(int j=0;j<a.length-1;j++) { if(min>a[j+1]) { min=a[j+1]; } } System.out.println(min); } } }



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-07-04 If you can't start, add a minimum initial value , With the minimum initial value, this big sword , A knife, a child
2021-05-11 My answer
2021-05-11 java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 Array out of bounds


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 142 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Basics - Array - Create an array Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot