Problem 8)(Java code) Give the output of the following program segment if: (a) x=1 and y=1, (b) x=2 and y=2. if (x > 1) if (y > 2) Sysytem.out.println(2*x-y); else Sysytem.out.println(2*x+y); else if (y > 2) Sysytem.out.println(x-y); else Sysytem.out.println(x+y);
(a) x=1 and y=1, x+y = 1 + 1 = 2 Output of the code is 2 Answer: 2 (b) x=2 and y=2. 2*x+y = 2*2 + 2 = 4+2 = 6 Output of the code is 6 Answer: 6
Problem 8)(Java code) Give the output of the following program segment if: (a) x=1 and y=1,...
18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
7. Write the following code segment in MARIE's assembly language (If-Else): If x < Y Then X = Y - X; Y = Y + 1; Else X = Y; Y = 0; Endif;
16. Verify the correctness of the following program segment with the assertions shown. x=z+1 y=x+2 y-6) if y >0 then z=y' + 1 else z=2*y end if (z = 7} 16. Verify the correctness of the following program segment with the assertions shown. x=z+1 y=x+2 y-6) if y >0 then z=y' + 1 else z=2*y end if (z = 7}
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
in java Assuming that x is 11 and y is 9, EXPLAIN why the output of the following code is ????? if (x < 10) if ( y < 10) System.out.println(“*****”); else System.out.println(“#####”); System.out.println(“?????”);
Python: 1) What output is generated by the following code segment? table = [["T", "U", "V"], ["W", "X", "Y"]] print(table[0]) Group of answer choices a- T b- ["T", "W"] c- ["T", "U", "V"] d- [["T", "U", "V"], ["W", "X", "Y"]] 2) Consider the following code segment: values = [4, 12, 0, 1, 5] print(values[1]) What is displayed when it runs? Group of answer choices a- 0 b- 1 c- 4 d- 12 3) Consider the following code segment: x =...
PLEASE SOLVE THESE QUESTIONS Q.3.6 What does the following code output? int x = 8; int y = 2; while(x > 8) { X- y+=2; } System.out.println(y); Q.3.7 What does the following code output? System.out.println((2 + 3 - 5) * (3/3) + (5+5)); Q.3.8 What does the following code output? if((2 == 2) && (3 != 3) && ((5 + 1)==6){ System.out.println(true); else { System.out.println(false);
OUTPUT IF: X = 10 Y = -5 X = 5 Y = -5 X = -15 Y = 5 Consider the following code segment, clearly showing a blank with a carat (™). What are the outputs? int x, y; cout << "This summer I am going to learn"; if (x > 10) cout << "swimming,"; else if (y > 0) cout << "surfing." else if (x > 0) cout << "dancing."; if (x <-10) cout << "spinning,"; else cout...
Write the following code segment in MARIE's assembly language: if X < 1 then Y = X - 2; X = 0; endif; Y = Y + 7;