Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Which of the following is equivalent to the code segment below? if (x > 2) x = x * 2; if (x > 4) x

Which of the following is equivalent to the code segment below?

if (x > 2) x = x * 2; if (x > 4) x = 0; 
if (x > 2) x *= 2;
if (x > 2) x = 0;
if (x > 2) x = 0; else x *= 2;
x = 0;

21

Which of the following is equivalent to the code segment below?

if (x > 0) x = -x; if (x < 0) x = 0; 
if (x<0) x = 0;
if (x < 0) x = 0; else x = -1;
if (x > 0) x = -x; else x = 0;
x = 0;
if (x>0) x = 0;

31

What would the following print?

int x = 3; int y = 2; if (x > 2) x++; if (y > 1) y++; if (x > 2) System.out.print("first "); if (y < 3) System.out.print("second "); System.out.print("third"); 
third
first second
first second third
first
first third

41

What would the following print?

int x = 3; int y = 2; if (y / x > 0) System.out.print("first "); System.out.print("second "); 
first
first second
second
Nothing will be printed

51

What would the following print?

int x = 3; int y = 2; if (y / x > 0); { System.out.print("first "); System.out.print("second "); } 
second
first second
Nothing will be printed
first

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions