Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Given the variable declarations below: byte myByte; int myInt; long myLong; c

ID: 3683717 • Letter: 5

Question

5. Given the variable declarations below:

byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;

Which one of the following assignments would need an explicit cast (choose all that appy)?
a) myInt = myByte;
b) myInt = myLong;
c) myByte = 3;
d) myInt = myChar;
e) myFloat = myDouble;

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

3. If s1 is declared as:
String s1 = "phenobarbital";
What will be the value of s2 after the following line of code executes?

String s2 = s1.substring( 3, 5 );

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

4. Which method below can change a String object, s ?

a. equals( s )

b. substring( s )

c. concat( s )

d. toUpperCase( s )

Explanation / Answer

5)


b) myInt = myLong;        //int is 4 byte and long is 8 byte
e) myFloat = myDouble; //float is 4 byte and double is 8 byte

hence corrected code is

b) myInt = (int)myLong;
e) myFloat = (float)myDouble;

3)

String s1 = "phenobarbital";
What will be the value of s2 after the following line of code executes?

String s2 = s1.substring( 3, 5 );

Ans: no (exclude the start index and include end index, so substring(3,5) gives 4th and 5th index character)

4)

Ans: c. concat( s )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote