
Respected sir ,what is the reason behind that java compiler gives me an error when float datatype isused to store float value?why we prefered double datatype for this?

You can use Scanner class. It is have a method nextFloat() which allow you to input float value.
import java.util.*;
class ScannerExample
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter float value: ");
float f=input.nextFloat();
System.out.println(f);
}
}