Java float Array

It is used to store float data type values only. With the following examples you can learn how to declare float array, how to assign values to float array and how to get values from float array.

Java float Array Example
/* float Array Example */
/* Save with file name FloatArray.java */

public class FloatArray
{
	public static void main(String args[])
	{
		//FLOAT ARRAY DECLARATION
		float f[];
		//MEMORY ALLOCATION FOR FLOAT ARRAY
		f = new float[4];
		//ASSIGNING ELEMENTS TO FLOAT ARRAY
		f[0] = 10.10f;
		f[1] = 30.3f;
		f[2] = 40.60f;
		f[3] = 77.50f;
		//FLOAT ARRAY OUTPUT
		System.out.println();
		System.out.println("float Array Example");
		System.out.println("==================");
		System.out.println();
		for(int i=0;i<f.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + f[i]);
		}
	}
}
                        

In this example you can learn how to assign values to float array at the time of declaration.

Java float Array Example 2
/* float Array Example 2 */
/* Save with file name FloatArray2.java */

public class FloatArray2
{
	public static void main(String args[])
	{
		//FLOAT ARRAY DECLARATION
		float f[] = {10.10f,30.3f,40.60f,77.50f};
		//FLOAT ARRAY OUTPUT
		System.out.println();
		System.out.println("float Array Example");
		System.out.println("==================");
		System.out.println();
		for(int i=0;i<f.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + f[i]);
		}
	}
}
                        

In this example you can learn how to declare float array with other float variables.

Java float Array Example 3
/* float Array Example 3 */
/* Save with file name FloatArray3.java */

public class FloatArray3
{
	public static void main(String args[])
	{
		//FLOAT ARRAY DECLARATION
		float f[], f2; //f IS AN ARRAY f2 IS NOT AN ARRAY
		//MEMORY ALLOCATION FOR FLOAT ARRAY
		f = new float[4];
		//ASSIGNING ELEMENTS TO FLOAT ARRAY
		f[0] = 10.10f;
		f[1] = 30.3f;
		f[2] = 40.60f;
		f[3] = 77.50f;
		f2 = 555.55f;
		//FLOAT ARRAY OUTPUT
		System.out.println();
		System.out.println("float Array Example");
		System.out.println("==================");
		System.out.println();
		System.out.println("f2 value is : "+f2);
		System.out.println();
		for(int i=0;i<f.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + f[i]);
		}
	}
}
                        

In this example you can learn how to assign float array to other float array.

Java float Array Example 4
/* float Array Example 4 */
/* Save with file name FloatArray4.java */

public class FloatArray4
{
	public static void main(String args[])
	{
		//FLOAT ARRAY DECLARATION
		float[] f, f2; //f AND f2 ARE ARRAY VARIABLES
		//MEMORY ALLOCATION FOR FLOAT ARRAY
		f = new float[4];
		//ASSIGNING ELEMENTS TO FLOAT ARRAY
		f[0] = 10.10f;
		f[1] = 30.3f;
		f[2] = 40.60f;
		f[3] = 77.50f;
		//ASSIGNING f ARRAY TO f2 ARRAY VARIABLE
		f2 = f;
		//FLOAT ARRAY OUTPUT
		System.out.println();
		System.out.println("float Array Example");
		System.out.println("==================");
		System.out.println();
		System.out.println("f array values");
		System.out.println();
		for(int i=0;i<f.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + f[i]);
		}
		System.out.println();
		System.out.println("f2 array values");
		for(int i=0;i<f2.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + f2[i]);
		}
	}
}