整数文字表示固定整数值,如:900、12、400、-222 等(在整数范围内)。
然而,浮点文字表示分数值,即具有十进制值的数字,如: 25.53、45.66、58.66 等。在编写这些文字时,应该使用符号 f
或 F
,如:25.55f
。
示例代码:
public class StringExample {
public static void main(String args[]){
int num1 = 111;
float num2 = 33.44f;
System.out.println("Value of integer:"+num1);
System.out.println("Value of integer:"+num2);
}
}
运行结果:
Value of integer:111
Value of integer:33.44