CodeHs Mid term (with complete solutions)
What is the output of this program? int sum = 1; Sln("Welcome to the adding machine!"); while(sum 10) { sum += sum; Sln(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) { Sln(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") { Sln("Hi Karel!"); } else { Sln("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) { Sln(i); } correct answers 10 7 4 {Unit 2}
Document information
- Uploaded on
- May 29, 2023
- Number of pages
- 9
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers