it is the same as an int, String, or any of the others:
float myVar = 5.7f;
If you try to assign a decimal number you must place an "f" at the end, otherwise Java will assume you are trying to assign a double.
float is a primitive datatype in java that is used to hold numeric values that contain decimal places.
Ex: float f = 10;
The above is an example declaration of a float variable. They can be used inall arithmetic operations like addition, subtraction, multiplication, division etc.
It uses 32 bits and there is as such no minimum or maximum value it can take. The value that a float can hold is larger than all possible numeric values that we can use in our systems (in most cases)
Perhaps you got an error message about a possible loss of precision?
The following will generate an error:
float f;
double d = 5.0;
f = d; // Here, there may be a loss of precision. The Java compiler will protest.
To solve this, tell Java that you (the programmer) know what you are doing, by using an explicit cast:
float f;
double d = 5.0;
f = (float) d; // Here, "d" is explicitly converted to type "float"
In C float a[8]; In Java float a[] = new float[8];
if u declare variable in method & tray to use this variable outside the method then it is out of scope
A variable declared as final can't be modified, once a value is assigned.
THIS IS FOR JAVA i don't know about anything about other languages yes it can be assignedthe syntax is:int (number) = (float) numberFOR EXAMPLE:int = a;a = (float ) 5.5;if the (float) is not there then in Java it gives an error saying precision loss of data type
Constants are defines using the final keyword.Variables are defined using the one of the keywords:charbooleanintdoublelongintStringTo use a constant you would have to put in something likedouble final pi = 3.14;
In C float a[8]; In Java float a[] = new float[8];
float myVariable = 20.1234;
if u declare variable in method & tray to use this variable outside the method then it is out of scope
int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.
A variable declared as final can't be modified, once a value is assigned.
You can declare them one by one. However, if you want to store lots of related data, you may want to consider using an array, where you use a single variable name (for example) for 1000 different items, and a number called an index to access the individual items.
THIS IS FOR JAVA i don't know about anything about other languages yes it can be assignedthe syntax is:int (number) = (float) numberFOR EXAMPLE:int = a;a = (float ) 5.5;if the (float) is not there then in Java it gives an error saying precision loss of data type
With the command return, followed by an object variable. In the method header, you have to declare the return type as the class of the object.
You declare a variable the same in a JSP as you do in a servlet. Let's say you want to declare a String variable called "foo" and you wanted to assign it a value of "bar." You would do this: String foo = "bar"; Of course, in a JSP, any Java code needs to be enclosed within <% and %>.
yes, float is keyword and data type in java
native is a key word used in java method. there is no variable as native in java
Constants are defines using the final keyword.Variables are defined using the one of the keywords:charbooleanintdoublelongintStringTo use a constant you would have to put in something likedouble final pi = 3.14;