java array variable

This time I will write about array variables.

What is an array variable?

The array is a collection of multiple values. An array variable is a method of putting it in a variable and using it.

Click here for an example

Example of array variable


public class Sample {
 
    public static void main(String[] args) {
         double[] d = new double[3];
         double sum,avg; //Variable to put total value and average value
         //Assign value
         d[0] = 1.2;
         d[1] = 3.7;
         d[2] = 4.1;
         sum = 0.0;
         for(int i = 0; i < d.length; i++){
             System.out.print(d[i] + " ");
             sum += d[i]; //You can sum the values with iterative syntax.
        }
        System.out.println();
        avg = sum / 3.0;
        System.out.println("Total value:" + sum);
        System.out.println("Average value:" + avg);
    }
}

The execution result is 1.2 3.7 4.1 Total value: 9.0 Average: 3.0 It will come out with.

Let's move on to the details.

Array declaration

First, declare the array.

Array declaration


(Variable type name) (Variable name)[] = new (Variable type name)[Number of arrays];
Or
(Variable type name) [](Variablename)=new(Variabletypename)[Number of arrays];

At the very beginning, I declared it in this way.

Excerpt


public static void main(String[] args) {
         double[] d = new double[3]; //Declared here. Type of double in variable d,The number of arrays is three.
         double sum,avg; 

Recommended Posts

java array variable
[Java] array
Java array
Java array
java (array)
Java array
[Java] Array
Java array
java array
[Java] Array
[Java] Array notes
Java variable scope (scope)
java variable declaration
Java variable scope
Regarding Java variable usage
About Java Array List
[Java ~ Array ~] Study memo 4
[Kotlin] Pass Kotlin Array as Java variable length argument [Java]
[Java] Variable name naming memo
[Java] List type / Array type conversion
Array
variable
About Java variable declaration statements
Java
Java Development Basics ~ Exercise (Array) ~
[Java] Convert ArrayList to array
Java
[Java Silver] Array generation method
How to initialize Java array
[Beginner] Java basic "array" description
Array
Java variable declaration, initialization, and types
Java learning memo (creating an array)
[Java] Output multidimensional array / spreadsheet (AOJ⑥ spreadsheet)
[Java] Declare and initialize an array
Java array variables are reference types
Java basic learning content 2 (array / ArrayList)
Java environment variable settings (Windows, AdoptOpenJDK11)
How to write Java variable declaration
Assign evaluation result to Java variable
[Java] Difference between array and ArrayList
[Java] Conversion from array to List
How to make a Java array
Java array / list / stream mutual conversion list
[Java] Convert array to ArrayList * Caution
Java learning (0)
Studying Java ―― 3
[Java] Annotation
When seeking multiple in a Java array
[Java] Module
[Ruby] Array
Java tips, tips
Array practice
Java methods
Java method
[Java] Multidimensional array / inner product calculation (AOJ⑦ inner product)
java (constructor)
Create variable length binary data in Java
[Java] ArrayDeque
static variable
java (override)