public class hw
//main
{
public static void
main(String [] args)
{
int x,y,a,b;
x=10;
y=10;
System.out.println("x++= " + x++ +":x= " +x);
System.out.println("--y= " + --y +":y= " +y);
a=17;
b=3;
System.out.println("r= " + a/b + ":r= " + (float)a/b + ":r= " + a/(float)b + " :r= " + (float)a/(float)b);
final double PI=3.14159;
double r;
r=4.0; //強制Double可以省略 因為r已經設為double了,反之若r為int 亦同
System.out.println("當r=4.0");
//強制資料型態為double時
System.out.println("圓周長=" + 2*(double)r*(double)PI + ";面積=" + (double)r*(double)r*(double)PI );
//強制資料型態為int時
System.out.println("圓周長=" + 2*(int)r*(int)PI + ";面積=" + (int)r*(int)r*(int)PI );
System.out.println(" ");
r=100.0;
System.out.println("當r=100.0");
//強制資料型態為double時
System.out.println("圓周長=" + 2*(double)r*(double)PI + ";面積=" + (double)r*(double)r*(double)PI );
//強制資料型態為int時
System.out.println("圓周長=" + 2*(int)r*(int)PI + ";面積=" + (int)r*(int)r*(int)PI );
}
}
留言列表