Word reserved "float" in Java

1

What is the FLOAT command in java for? They left me an exercise where I have to capture enrollments, names and the 3 student ratings and then give the user the option to consult them when entering the student's enrollment and request to use the float command to achieve this. My question is what is it for and how is it used? The teacher wrote this as an example:

float c1[]=new float[20]
float c2[]=new float[20]
float c3[]=new float[20]
    
asked by Stephanie B Bautista 02.03.2017 в 15:29
source

2 answers

2

float is one of the primitive Java types. It serves to store numbers with floating point and has a precision of 32 bits. To define and initialize a variable type float you do as follows:

float numero = 1.5f; //la F al final es importante, indica que es un float.
System.out.println("Valor de número: " + numero);

What you have in your teacher's example is an array of float . Consider that each element of your array must have elements of type float . To continue her example:

float c1[]=new float[20];
c1[0] = 1.1f;

For more information, you can check the official Java guide: Primitive Data Types

    
answered by 02.03.2017 / 15:32
source
-2

The ratings are usually numbers with an integer part and a decimal part, for example, 3.5 or 5.0 or 4.8 and can be stored in a variable float type in java, this is a form:

float c1=3,5;
float c2=5,0;
float c3=4,8;

Your code has brackets [] or square brackets [] indicating that more than one value is stored on those variables, for this case, 20 float values.

float c1[]=new float[20];
float c2[]=new float[20];
float c3[]=new float[20];

This means that 20 float numbers are stored in the variable c1, 20 float numbers in the variable c2 and 20 float numbers in the variable c3. Locate each grade in one of the 20 positions with the [] the difference between them and can logically indicate that these qualifications belong to a certain student. For example, the following code shows the three grades for the first student:

float c1[0]=3,5;
float c2[0]=5,0;
float c3[0]=4,8;
    
answered by 02.03.2017 в 16:10