Code:
// ap6,運算式的型態轉換 public class ap6 { public static void main(String args[]) { short s=-5; int i=6; float f=9.67f; double d=976e-2; //9.76 System.out.print("(short*integer)="); System.out.println((s*i)); System.out.print("(double/float)="); System.out.println((d/f)); System.out.print("(integer+float)="); System.out.println((i+f)); System.out.print("(double/float)*(integer+float)="); System.out.println((d/f)*(i+f)); System.out.println(" "); System.out.print("(s*i)-(d/f)*(i+f)="); // 印出結果 System.out.println((s*i)-(d/f)*(i+f)); /* ((short*integer)->short)=-30 ((double/float)->double)=1.00930712750734 ((integer+float)->double)=15.67 ((double/float)*(integer+float)->double)=15.81584276504404 ((s*i)-(d/f)*(i+f)->short-double=double)=-45.81584276504404 */ } }
Output:
(short*integer)=-30 (double/float)=1.00930712750734 (integer+float)=15.67 (double/float)*(integer+float)=15.81584276504404 (s*i)-(d/f)*(i+f)=-45.81584276504404 Press any key to continue...
Discuss:
0 comments:
Post a Comment