Ask coding questions

← Back to all posts
why can't i use both float and double in same progrram
AnkitaSingh4 (0)

i want to calculate area of rectangle so
float length=8.9
double breadth = 9.7
double area = length*breadth
i want to use both float and double in my program.

mwilki7 (1078)

Do you have the correct repl linked? I don't see any floats or doubles.
Anyhow, the program should be able to run anyway, make sure to do appropriate casting (for instance: float b = (float) 5.5;)

Here is an example snippet:

public class Main
	public static void main(String[] args) 
		System.out.println("Hello World");
		double d = 5.5;
		float f = (float)6.5;
		System.out.println(f + d);


Hello World