Cs21-midterm exam with completej j j
solutions 2024
j j
Files jthat jcontain jJava jbytecodes jfor jexecution jmust jhave jthe jextension j-
jANSWER✓✓-.class
The j___ jwindow jis ja jspecial jtext-only jwindow jin jwhich jJava jprograms jinteract
jwith jthe juser j- jANSWER✓✓-console
Java jrequire jthe jname jof jthe jfile jcontaining ja jprogram jmust jbe jthe jsame jas
jthe jname jof jthe jclass jdefined jin jthe jfile. j- jANSWER✓✓-True
In jjava, jwhat jcharacter jdo jall jescape jsequences jbegin jwith j? j- jANSWER✓✓-
backslash
A j__________ jis ja jprogram jthat jtranslates ja jcomputer jprogram jwritten jin jone
jlanguage jinto jan jequivalent jprogram jin janother jlanguage. j- jANSWER✓✓-
compiler
In jJava, jwhat jsymbols jare jused jto jcontain jall jmethods jwithin ja jclass jand jall
jlines jof jcode jwithin ja jmethod? j- jANSWER✓✓-curly jbrackets{}
In jJava, jthe jmethod jnamed j__________ jis jthe jstarting jpoint jfor jexecution. j-
jANSWER✓✓-main
In jJava, jwhat jsymbol jis jused jto jterminate jeach jstatement jof jcode jin ja
jprogram? j- jANSWER✓✓-semi-colon
________ jerrors jare jso jsevere jthat jJava jstops jyour jprogram jfrom jexecuting. j-
jANSWER✓✓-Runtime
Which jof jthe jfollowing jcharacters jis jNOT jallowed jas jthe jfirst jletter jof ja jJava
jidentifier? j- jANSWER✓✓-A jdollar jsign
Which jof jthe jfollowing jis ja jvalid jJava jstatement jfor jmultiplying jthe jinteger
jvariable jz jby j2? j- jANSWER✓✓-z j= jz*2; jz*=2
Declaring jmore jthan jone jvariable jin ja jsingle jdeclaration jstatement jis jallowed jin
jJava, jas jlong jas jall jthe jvariables jare jof jthe jsame jtype. j- jANSWER✓✓-True
, What jis jthe jvalue jof jx jafter jthe jfollowing jline jof jJava jcode jis jexecuted?
int jx j= j7 j- j(5 j+ j18 j/ j5) j+ j2 j* j(11 j% j6 j- j1); j- jANSWER✓✓-7
What jis jthe jvalue jof jx jafter jthe jfollowing jline jof jJava jcode jis jexecuted?
int jx j= j7 j- j(5 j+ j18 j/ j5) j+ j2 j* j11 j% j6 j- j1; j- jANSWER✓✓-2
If ja jvariable jis jdeclared jwithin ja jfor jloop, jthat jvariable jcan jstill jbe jaccessed
jafter jthe jloop jis jcompleted. j- jANSWER✓✓-False
The jproper jorder jof jthe jthree jelements jwithin jthe jparentheses jat jthe jbeginning
jof ja jfor jloop jare: jInitialization, jUpdate, jContinuation jTest. j- jANSWER✓✓-False
Type jcasting jmust jbe jused jin jJava jwhen jassigning jan jinteger jvalue jto ja
jfloating-point jvariable. j- jANSWER✓✓-False
In jJava, jvariables jmust jonly jbe jdeclared jone jtime. j- jANSWER✓✓-True
In jJava, jthe joperation j37 j/ j3 jwill jreturn jthe jvalue j12. j- jANSWER✓✓-True
The jthree jelements jwithin jthe jparentheses jat jthe jbeginning jof ja jfor jloop jmust
jbe jseparated jby j__________. j- jANSWER✓✓-Semi-colons
Given jthe jfollowing jJava jcode,
double jx j= jMath.floor(7.3);
the jvalue jof jthe jvariable jx jwill jbe j7. j- jANSWER✓✓-True
Suppose jyou jhave jdeclared ja jdouble jvariable jcalled jx jin ja jJava jprogram.
jWhich jis jthe jproper jway jto jset jx jequal jto jthe jsquare jroot jof j2 jby jusing jJava's
jsqrt jmethod? j- jANSWER✓✓-x j= jMath.sqrt(2)
Given jthe jfollowing jJava jcode,
double jx j= jMath.ceil(7.3);
the jvalue jof jthe jvariable jx jwill jbe j7. j- jANSWER✓✓-False
In jjava, jStrings jare jimmutable j- jANSWER✓✓-True
When jthe jfollowing jJava jcode jexecutes:
String jword j= j"Barcelona";
String jpart j= jword.substring(4,9);
solutions 2024
j j
Files jthat jcontain jJava jbytecodes jfor jexecution jmust jhave jthe jextension j-
jANSWER✓✓-.class
The j___ jwindow jis ja jspecial jtext-only jwindow jin jwhich jJava jprograms jinteract
jwith jthe juser j- jANSWER✓✓-console
Java jrequire jthe jname jof jthe jfile jcontaining ja jprogram jmust jbe jthe jsame jas
jthe jname jof jthe jclass jdefined jin jthe jfile. j- jANSWER✓✓-True
In jjava, jwhat jcharacter jdo jall jescape jsequences jbegin jwith j? j- jANSWER✓✓-
backslash
A j__________ jis ja jprogram jthat jtranslates ja jcomputer jprogram jwritten jin jone
jlanguage jinto jan jequivalent jprogram jin janother jlanguage. j- jANSWER✓✓-
compiler
In jJava, jwhat jsymbols jare jused jto jcontain jall jmethods jwithin ja jclass jand jall
jlines jof jcode jwithin ja jmethod? j- jANSWER✓✓-curly jbrackets{}
In jJava, jthe jmethod jnamed j__________ jis jthe jstarting jpoint jfor jexecution. j-
jANSWER✓✓-main
In jJava, jwhat jsymbol jis jused jto jterminate jeach jstatement jof jcode jin ja
jprogram? j- jANSWER✓✓-semi-colon
________ jerrors jare jso jsevere jthat jJava jstops jyour jprogram jfrom jexecuting. j-
jANSWER✓✓-Runtime
Which jof jthe jfollowing jcharacters jis jNOT jallowed jas jthe jfirst jletter jof ja jJava
jidentifier? j- jANSWER✓✓-A jdollar jsign
Which jof jthe jfollowing jis ja jvalid jJava jstatement jfor jmultiplying jthe jinteger
jvariable jz jby j2? j- jANSWER✓✓-z j= jz*2; jz*=2
Declaring jmore jthan jone jvariable jin ja jsingle jdeclaration jstatement jis jallowed jin
jJava, jas jlong jas jall jthe jvariables jare jof jthe jsame jtype. j- jANSWER✓✓-True
, What jis jthe jvalue jof jx jafter jthe jfollowing jline jof jJava jcode jis jexecuted?
int jx j= j7 j- j(5 j+ j18 j/ j5) j+ j2 j* j(11 j% j6 j- j1); j- jANSWER✓✓-7
What jis jthe jvalue jof jx jafter jthe jfollowing jline jof jJava jcode jis jexecuted?
int jx j= j7 j- j(5 j+ j18 j/ j5) j+ j2 j* j11 j% j6 j- j1; j- jANSWER✓✓-2
If ja jvariable jis jdeclared jwithin ja jfor jloop, jthat jvariable jcan jstill jbe jaccessed
jafter jthe jloop jis jcompleted. j- jANSWER✓✓-False
The jproper jorder jof jthe jthree jelements jwithin jthe jparentheses jat jthe jbeginning
jof ja jfor jloop jare: jInitialization, jUpdate, jContinuation jTest. j- jANSWER✓✓-False
Type jcasting jmust jbe jused jin jJava jwhen jassigning jan jinteger jvalue jto ja
jfloating-point jvariable. j- jANSWER✓✓-False
In jJava, jvariables jmust jonly jbe jdeclared jone jtime. j- jANSWER✓✓-True
In jJava, jthe joperation j37 j/ j3 jwill jreturn jthe jvalue j12. j- jANSWER✓✓-True
The jthree jelements jwithin jthe jparentheses jat jthe jbeginning jof ja jfor jloop jmust
jbe jseparated jby j__________. j- jANSWER✓✓-Semi-colons
Given jthe jfollowing jJava jcode,
double jx j= jMath.floor(7.3);
the jvalue jof jthe jvariable jx jwill jbe j7. j- jANSWER✓✓-True
Suppose jyou jhave jdeclared ja jdouble jvariable jcalled jx jin ja jJava jprogram.
jWhich jis jthe jproper jway jto jset jx jequal jto jthe jsquare jroot jof j2 jby jusing jJava's
jsqrt jmethod? j- jANSWER✓✓-x j= jMath.sqrt(2)
Given jthe jfollowing jJava jcode,
double jx j= jMath.ceil(7.3);
the jvalue jof jthe jvariable jx jwill jbe j7. j- jANSWER✓✓-False
In jjava, jStrings jare jimmutable j- jANSWER✓✓-True
When jthe jfollowing jJava jcode jexecutes:
String jword j= j"Barcelona";
String jpart j= jword.substring(4,9);