Question

Problem 8)(Java code) Give the output of the following program segment if: (a) x=1 and y=1,...

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);
0 0
Add a comment Improve this question Transcribed image text
Answer #1
(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
Add a comment
Know the answer?
Add Answer to:
Problem 8)(Java code) Give the output of the following program segment if: (a) x=1 and y=1,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    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*...

    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;...

  • 1. In java (What is the output of the code segment)? public static void Main(){    ...

    1. In java (What is the output of the code segment)? public static void Main(){             int x = 38;     int y = 45;         int z = DoIt(ref x, ref y);     PRINTLINE(x + “ “ + y + “ “ + z); // PRINTLINE 1 } static int DoIt(ref int a, ref int b) { a /= 6; b /= 8; PRINTLINE(a + “ “ + b); // PRINTLINE 2 return (a + b); } 2....

  • 7. Write the following code segment in MARIE's assembly language (If-Else): If x < Y Then...

    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...

    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,...

    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...

  • What will be the output of the following code segment after the user enters 0 at...

    What will be the output of the following code segment after the user enters 0 at the keyboard in a C++ program? int x = -1; cout << "Enter a 0 or 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;

  • What is the output from the following code segment? Output from PRINTLINE 1: public static void...

    What is the output from the following code segment? Output from PRINTLINE 1: public static void Main(){             int x = 38;     int y = 45;         int z = DoIt(ref x, ref y);     PRINTLINE(x + “ “ + y + “ “ + z); // PRINTLINE 1 } static int DoIt(ref int a, ref int b) { a /= 8; b /= 7; PRINTLINE(a + “ “ + b); // PRINTLINE 2 return (a + b);...

  • in java Assuming that x is 11 and y is 9, EXPLAIN why the output of...

    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"],...

    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 =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT