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
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
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
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 } }
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 : "); } }
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
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
3 One answer
Spicy chicken with vegetables Jump to the problem location Answer time :2021-10-22 Pipi Jump to the problem location Answer time :2021-10-16 es54 Jump to the problem location Answer time :2021-10-13
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2021-10-04
code
4 One answer
Pipi Jump to the problem location Answer time :2021-10-16 Kion11 Jump to the problem location Answer time :2021-10-12 Fengtai Wu Qilong Jump to the problem location Answer time :2021-10-12 Makino li Jump to the problem location 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
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
|