Java Data Types: int, float, double and More

Java · Lesson 3 of 22

Java has two types for decimal numbers. float uses 32 bits and needs an f at the end of a value, for example 10.8f. double uses 64 bits and is more precise, so it is the usual choice for decimals.

The example below calculates the area of a circle using the formula pi x r x r and prints the result.

Float In Java

Example : DoubleDemo

class DoubleDemo {
	public static void main(String args[]) {
	double a;
	float r = 10.8f,pi = 3.1416f;
	a = pi*r*r;
	System.out.println("Area of circle is"+a);
	}
}
Unit-2 Data Types In Java illustration
OUTPUT : DoubleDemo

Test what you learned

1 free Java test with instant scores.

Take a Java test

More Java lessons

Learn it in a course

WhatsApp us