The variable which is declared using 'float' data type can store decimal values. But the only thing to observe is that the value should end with letter f as shown in the below program.
public static void main(String args)
float a=123.456f; //Observe that the value to be stored in the float declared variable should end with 'f' letter.
Output of this program:
Try this program without adding the letter f at the end of the value. Observe that the program will throw an error on compiling the program.
Please comment below to feedback or ask questions.
How to use the 'char' data type will be explained in the next post.