float variables initialization java

前端 未结 6 1103
面向向阳花
面向向阳花 2021-01-23 04:17

The following code snippet gave me compiler error at Line 1.

public abstract class xyz
{

    float Gamma = 20.0; //Line 1
    public class Alpha
    {
        v         


        
6条回答
  •  醉话见心
    2021-01-23 04:35

    float density = 20.0f;

    If you try to assign a decimal number you must place an "f" at the end, otherwise Java will assume you are trying to assign a double .A double would more precisely cover more numbers that you could type in.

提交回复
热议问题