In this tutorial, we will discuss about the float keyword in java programming language
In the java language, float keyword is used to declare a variable as a numeric type. float is a primitive data type which is used to store 32 bit float data type.
syntax of float data type declaration
float <variable_name> = <float_value>;
Example of float keyword for variable declaration
float average = 45.87;
The float keyword can be used to declare return type of a method.
Syntax of float method
<access_modifier> <return_type> <method_name>; { return <method_name>; }
Example of float method
public float getAverage(){ return getFirstAverage; }
Above method is a float method which does return any value.
Example float method within class
public class Example _float{ // this is a class in java public static void main(String args[]){ // this is main method in java } public float add(){ // this is a float method which is return value; } }
Program 1
public class float_Keyword{ public static void main(String args[]){ float d1=35.87f; //float keyword is used as variable float d2=43.6f; float result=d1+d2; System.out.println("The result is :"+result); } }
When the above code is compiled and executed, it will produce the following results
The result is : 79.47
program 2
public class float_Keyword1{ public static void main(String args[]){ add(14.56f,46.7f); } static float add(float a,float b){ //float keyword is used with method float result=a+b; System.out.println("The result is :"+result); return result;//return value } }
When the above code is compiled and executed, it will produce the following results
The result is : 61.260002
There are other Java language keywords that are similar to this keyword
static keyword in Java language
extends keyword in Java language
Suggested for you
Usage of final keyword in Java
Finally keyword in Java language
s
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…