早教吧 育儿知识 作业答案 考试题库 百科 知识分享

一道关于包装类的JAVA选择题Whichthreearevaliddeclarationsofafloat?(ChooseThree)A.Floatfoo=-1;B.Floatfoo=1.0;C.Floatfoo=42e1;D.Floatfoo=2.02f;E.Floatfoo=3.03d;F.Floatfoo=0x0123;Answer:A,D,F麻烦帮

题目详情
一道关于包装类的JAVA选择题
Which three are valid declarations of a float? (Choose Three)
A. Float foo = -1;
B. Float foo = 1.0;
C. Float foo = 42e1;
D. Float foo = 2.02f;
E. Float foo = 3.03d;
F. Float foo = 0x0123;
Answer: A, D, F
麻烦帮我看下为什么选ADF
▼优质解答
答案和解析
A float foo =-1,-1是int类型,可以自动向上转换为float.
B float foo =1.0,1.0默认是double类型,必须强制向下转换为float.
C float foo=42e1.42e1为double类型,必须强制向下转换为float.
F float foo=0x0123.0x0123为16进制,转换为10进制后会自动向上转换为float.