Question

In Java 1. What will be the value of x after the following section of code...

In Java

1. What will be the value of x after the following section of code executes:

int x = 3;

if (x > 3)

    x = x – 2;

else

    x = x + 2;

A. 1 B.3    C.5              D.7

2. What will be the value of y after the following section of code executes:

int y = 5, z = 3;

if (y > 4){

     z = 2;

     y = y – 1;

}else

     z = 1;

y = z;

A. 1 B.2    C.3              D.4

Homework Answers

Answer #1

Thank you for asking the question.

1. Value of x after the given code executes is 5.

Explaination:- As initially x=3.Therefore else part will execute rather than "if part" because x is not greater than 3. So the final value of x is x=x+2 => 3+2=5. So,option c is correct.

2. Value of y after executing given code is 2.

Explaination:- As initially y=5 and z=3. Therefore y>4, that's why " if " part will execute.

So, on executing "if" part, z will be 2 and y=y-1 =>y=5-1=4.

At last, y=z and z is equal to 2. So , y is assigned as 2.

Correct answer is option B. 2

# Thank you for asking the question.

# Feel free to ask any doubt and once again thank you very much.

Know the answer?
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
Similar Questions
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
C++ What is the value of average after the following code executes? double average; average =...
C++ What is the value of average after the following code executes? double average; average = 4.0 + 3.0 * 2.0 + 1.0; Consider the following function: int compute(int n) { int x = 1; for (int i = 1; i <= n; i++) { x *= i; } return x; } What is the returned value for the following function call? int value = compute(4); What is the value of number after the following statements execute? int number; number...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!! QUESTION 1 What is the output after the code executes? Assume there are no syntax errors and the code will compile. int x = 10; do { System.out.println ( x ); x -= 3; } while (x > 0); A. 10 7 4 1...
JAVA What values are stored in variables a and b in the code below? public class...
JAVA What values are stored in variables a and b in the code below? public class StackQuestion { public static void main(String[] args) { Stack s = new Stack(); s.push(1); s.push(2); s.push(3); s.pop(); s.pop(); s.push(4); s.push(5); s.pop(); s.pop(); int a = s.pop(); s.push(6); int b = s.pop(); } } What numbers are stored in variable a and b when the code below executes? public class QueueQuestion { public static void main(String[] args) { Queue s = new Queue(); s.enqueue(1); s.enqueue(2);...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } } Select one: a)Each case section must end with a break statement. b)The case label 0 must precede case label 1. c)There is nothing wrong with the Java code. d)The default label must be the last label in the switch statement. e)The variable x does...
java: can anyone explain. why does my code print out ##### and ***** instead of just...
java: can anyone explain. why does my code print out ##### and ***** instead of just #####? int a=1, b=2, c=3;    if(a<b) System.out.println("####"); else System.out.println("&&&&"); System.out.println("****");
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
Write the java code that will convert the given Before links to the After links with...
Write the java code that will convert the given Before links to the After links with comments. For example: Before:            +----+----+    +----+----+ list ----> | 1 | +----> | 2 | / |            +----+----+    +----+----+ After:            +----+----+    +----+----+    +----+----+ list ----> | 1 | +----> | 2 | +----> | 3 | / |            +----+----+    +----+----+    +----+----+ Code: (example answer) list.next.next = new ListNode(3, null);   // 2 -> 3 (1) Before:            +----+----+    +----+----+ list ---->...
Draw a memory diagram of the variables of the following code after the execution of the...
Draw a memory diagram of the variables of the following code after the execution of the code. Please draw in form of array auto x = 3, y = -1; ++x; y--; auto z = 2 * (x + y); x = z / y; y = 1 - x;
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT