Question

In: Computer Science

no need to explain 11. What is output by the following code segment? boolean isHighTemp =...

no need to explain

11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot

12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”); }while (???) A) n < 10 B) n = 2

13. In Java, the value of the expression 23 % 6 is: A) 5 B) 2 C) 3 D) 4

14. Given the constant declaration final int CAPACITY = 10; which of the following is NOT a valid use of CAPACITY? A) CAPACITY += CAPACITY; B) CAPACITY = 100; C) int currentSize = CAPACITY + 9; D) A and B above

15. Given the following declaration and the method header for the Max method double x, y, z; Page 4 double Max(double, double); which of the following shows a syntactically invalid call to Max method: A) z = Max(x, y); B) z = Max((x+y+z); C) System.out.print(Max(x, (y+x) )); D) z = y + Max((y-x), (x+y));

Solutions

Expert Solution

11.

Answer: Not Hot(B)

here we declared degree=100.01

if(degree>=110) which is false 100.01<110

so else statement will be executed which is Not Hot

12.

Answer:A(n<10)

In the while loop we have to write the condition

which is n<10  

if we write n=2

which is not a condition then it will became a infinet do while loop

so the answer is n<10

13.

Answer :(A) 5

% operator return the remonder of the division

here we use 23%6 the reminder when we divide 23/6 is 5

so the answer is 5

14.

Answer:(D) A and B above

because when you declare a variable with final keyword then

you cannot assign any value to it

but in option A we write CAPACITY+=CAPACITY here we are assigning the value to the final variable

which cannot be done

in option B we write CAPACITY=100 here also we are assigning the value to final variable

which cannot be done

so the answer is boath a and b

15.

Answer:(B)

z = Max((x+y+z);

Here we have to pass 2 parameter to the MAX function

and we are missing a closing )

so option is B is syntactically invalid


Related Solutions

21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back('...
what is the expected output of the following segment of code? dq = Deque() dq.push_back('M') dq.push_back(' ') l = ['A', 'L', 'E', 'S', 'T', 'E'] for i in l: → if ord(i) % 3 == 0: → → dq.push_back(i) → elif ord(i) % 5 == 0: → → dq.push_front(i) → → dq.push_back(i) → elif ord(i) % 4 == 0: → → dq.push_back(i) → else: → → dq.peek_front() → → dq.push_front('X') → → dq.push_back('R') dq.push_front(dq.peek_back()) dq.pop_back() print(dq)
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.int count = 0;do{++ count;if (count == 2)Blank;cout << count << " ";} while (count <= Blank);cout << endl;
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
What output is produced by the following code?   Explain how it works. public class A {...
What output is produced by the following code?   Explain how it works. public class A { int a = 1; int b = 2; public int getSum(int a, int b) {     this.a+=a;     this.b+=b;     return this.a + this.b; } } public class B extends A { int a = 3; int b = 4; public int getSum(int a, int b) {     this.b=a;     super.b=b+b;     return super.a+this.b; } } public class q2 { public static void main(String[]...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
What output is produced by the following code? Explain how it works (at least 5 lines)....
What output is produced by the following code? Explain how it works (at least 5 lines). class Super { int num = 1; int id = 2; } class Sub extends Super { int num = 3; public void display() { System.out.println(num); System.out.println(super.num); System.out.println(id); } } public class Inheritance1 { public static void main (String[] args) { Sub obj = new Sub(); obj.display(); } } =============================== Example of "Explain how it works" Sample Question: What output is produced by the...
What output is produced by the following code? Explain how it works (at least 5 lines)....
What output is produced by the following code? Explain how it works (at least 5 lines). class Super { int num = 1; int id = 2; } class Sub extends Super { int num = 3; public void display() { System.out.println(num); System.out.println(super.num); System.out.println(id); } } public class Inheritance1 { public static void main (String[] args) { Sub obj = new Sub(); obj.display(); } } =============================== Example of "Explain how it works" Sample Question: What output is produced by the...
What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT