1 public class Text { 2 3 public static void main(String args[] ){ 4 float x=123.45; 5 System.out.println(x); 6 } 7 }
不加F默認是double類型,取值范圍從大范圍(double)向小范圍(float)需要強制轉換,報錯如下:

同理long類型也需要加L,不加默認int,賦值范圍超過int類型取值范圍不加L編譯器報錯,不超過int取值范圍不會報錯,因為不加L則默認為int型(float除非賦值整數,否則都會報錯)。
