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)
Given the following code segment, tell the output if it is part of an executable program....
Given the following code segment, tell the output if it is part of an executable program. Assume the addresses of the variables, a and b, are 0012A32A and 0012A340, respectively.        int* intPtr1, *intPtr2;        int a = 10, b;        intPtr1 = &a;        cout<< "The data in a is "<<a<<endl;        cout << "The address of a is "<<&a<<endl;        cout <<"The data in intPtr1 is "<< intPtr1 <<endl;        cout <<"The data in the variable pointed by...
What would the output be for the following program code segment? #define ROWS  3      #define COLS 3...
What would the output be for the following program code segment? #define ROWS  3      #define COLS 3 void addCoulmns(int arr[][COLS],int Sum[COLS]); int main(void) {        int array[ROWS][COLS] = {{ 10, 35, 23 },                                   { 5, 4, 57 },                                   { 4, 7, 21 }};        int ColSum[ROWS];        int rows;        int columns;        addCoulmns(array,ColSum);        for (columns = 0; columns < COLS - 1; columns++)               printf("%d\n",ColSum[columns]);        return(0); } void addCoulmns(int arr[][COLS],int Sum[COLS]) {        int row;        int col;        for (col = 0; col < COLS -...
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;
What is the output of the following code? Explain your answer in a paragraph or two....
What is the output of the following code? Explain your answer in a paragraph or two. class ExceptionThrown { static int divideByZero(int a, int b){ int i = a/b; return i; }    static int computeDivision(int a, int b) { int res =0; try{    res = divideByZero(a,b); } catch(NumberFormatException ex){ System.out.println("NumberFormatException is occured"); }    return res; }    public static void main(String args[]){ int a = 1;    int b = 0; try{ int i = computeDivision(a,b); }...
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; } }...
The output of the following code is "11 0" But I am not sure why, can...
The output of the following code is "11 0" But I am not sure why, can someone please explain to me clearly and concisely why this is the case? main(){ int n=1; if(fork()) wait(&n); else n=n+10; printf("%d\n", n); exit(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[]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT