public class Test {
public static void main(String[] args) {
int a = 155;
int b = 9;
float g,h,k;
System.out.println("a= "+a+" b= "+b);
System.out.println("a/b= "+a/b);
g = a/b;
System.out.println("g = a/b = "+ g);
h = (float)a/b;
System.out.println("h = (float)a/b = "+h);
k = (float)(a/b);
System.out.println("k = (float)(a/b) = "+k);
}
}
输出结果
a= 155 b= 9
a/b= 17
g = a/b = 17.0
h = (float)a/b = 17.222221
k = (float)(a/b) = 17.0