<> Zero , Single choice
* In the following character face values , It's illegal ?
D. ‘ course ’
Answer and analysis ： This paper examines the representation of character face value , Character literals are enclosed in single quotation marks , And you can only have one character in a single quotation mark , It can be Chinese characters . therefore ABD The content of the option is correct . Enclosed in double quotation marks is the literal value of a string , therefore C The content of the option is illegal , This question chooses the illegal character type literal value representation , So choose C.
* Which of the following is the correct representation of character literal values ?
Answer and analysis ： This paper examines the representation of character face value , The correct expression is ： Use single quotation marks , And it can only have one character , therefore B The option is correct .A Option has no single quotation marks ,C Options are enclosed in single quotation marks with two characters ,D The option is enclosed by two characters in double quotation marks , Is the representation of a string .
* In the following variable definitions , The wrong thing is ?
A. int a;b;
B. float a,b1=1.23f;
C. char ch1=‘a’,ch2=’\n’;
D. int n=100,m=2,k;
Answer and analysis ： The definition of variables is examined in this paper , When multiple variables are defined at the same time , Variable names are separated by commas , therefore A The option is wrong . The other options are the correct form of variable definition .
* In the following variable definitions , The right thing is ?
A. boolean b=”false”
B. float f=5.6;
C. byte x=343;
D. double d=5.3f;
Answer and analysis ： The definition of variables is examined in this paper .A Wrong option , The literal value of a boolean type , Double quotation marks are not allowed .B option ,float
f=5.6; The statement is incorrect ,5.6 yes double Type literal value , Assign to float Type will report error .C option ,343 Beyond byte Data representation range of type , therefore byte
x=343 A compilation error will occur . hold float The literal value of the type is assigned to the double Variables of type are OK , therefore D option double d=5.3f It's right .
<> One , Multiple choice
* Which two are legal string literals ?
Answer and analysis ： This paper examines the representation of the literal value of a string , String literal values should be enclosed in double quotation marks .BC The options are in single quotation marks , So it's not true .A Option is to represent an empty string .D The option is only one in the string Unicode Represents the character , It is equivalent to only one character in a string .
* Which two statements are true ?
A. char ch=65539;
B. int n=5.6f;
C. double d=1.2f;
D. double d=1.23;float f=(float)d;
Answer and analysis ： This question examines the conversion of data types .A option ,65539 The data range represented by character type is out of range , So the statement is wrong .B option , take float The data of type is assigned to int The type will also report an error .C option , You can float Type data assigned to double Type variable , Automatic type conversion is performed .D Options will double Type data assigned to float Type variable , Cast is OK .