QUESTIONS WITH ANSWERS |\ |\
What is the output of this program?
|\ |\ |\ |\ |\ |\
int sum = 1;
|\ |\ |\ |\
System.out.println("Welcome to the adding machine!"); |\ |\ |\ |\ |\
while(sum < 10) |\ |\ |\
{ |\
|\ sum += sum;
|\ |\ |\
|\ System.out.println(sum); |\
} - CORRECT ANSWERS ✔✔Welcome to the adding
|\ |\ |\ |\ |\ |\ |\ |\
machine! {Unit 2} |\ |\
2
4
8
16
What is the output of this for loop?
|\ |\ |\ |\ |\ |\ |\
for(int i = 0; i < 100; i += 2)
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
{ |\
|\ System.out.println(i); |\
,} - CORRECT ANSWERS ✔✔The even numbers from 0 to
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
98, inclusive {Unit 2}
|\ |\ |\
What is the proper syntax to initialize a double called
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
temperature to have the value 70.4? - CORRECT |\ |\ |\ |\ |\ |\ |\ |\
ANSWERS ✔✔double temperature = 70.4; {Unit 2} |\ |\ |\ |\ |\ |\
Which of the following is not a primitive type? - CORRECT
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
ANSWERS ✔✔String {Unit 2} |\ |\ |\
What in this code segment could potentially cause a bug
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
in our program?
|\ |\
String myString = readLine("What is your name?");
|\ |\ |\ |\ |\ |\ |\
if (myString == "Karel")
|\ |\ |\ |\
{ |\
|\ System.out.println("Hi Karel!"); |\ |\
} |\
else |\
{ |\
|\ System.out.println("You're not Karel!"); |\ |\ |\
} - CORRECT ANSWERS ✔✔Comparing Strings with ==
|\ |\ |\ |\ |\ |\ |\ |\
instead of the .equals method. {Unit 2} |\ |\ |\ |\ |\ |\
, Which of these is not a logical operator? - CORRECT
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\
ANSWERS ✔✔++ {Unit 2} |\ |\ |\
What is the output of this for loop?
|\ |\ |\ |\ |\ |\ |\
for(int i = 10; i > 2; i -= 3) |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
{ |\
|\ System.out.println(i); |\
} - CORRECT ANSWERS ✔✔10
|\ |\ |\ |\
7
4
{Unit 2} |\
What will the values of x and y be after this code segment
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
runs?
|\
int x = 100; int y = 100; if (x <= 100)
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
{ |\
|\ if (y > 100)
|\ |\ |\
|\ { |\
|\ x = 200;
|\ |\ |\
|\ } |\
|\ else |\
|\ {