Question

What will be the value of x after the following code is executed? int x =...

What will be the value of x after the following code is executed?

int x = 5;

while (x <50)

{

x += 5;

}

a) 50

b) 45

c) Infiniteloop

d) 55

Given the following code segment: Scanner in = new Scanner (System.in);

boolean done = false;

while (!done)

{

int input = in.next();

if(input.equalsIgnoreCase("q"))

done = false;

}

What will cause the loop to terminate?

a) When the user enters -1

b) The loop will never terminate

c) When the user enters q or Q

d) When the user enters done

How many times will this for loop execute?

for (int i = 2; i < 10; i +=3)

{

...

}

a) 6

b) 3

c) 5

d) 4

A package is any program with two or more classes: True or False

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Que1: What will be the value of x after the following code is executed?

int x = 5;

while (x <50)

{

x += 5;

}

a) 50

b) 45

c) Infiniteloo

Answer -: Option A - 50

1 public class Main 3 public static void main(String[] args) f 4 int x = 5; while (x <50) 7 8 9 10 x += 5; System , .out.println(x); 12 inp 50 Program finished with exit code 0 Press ENTER to exit console.L

Question 2 : Given the following code segment: Scanner in = new Scanner (System.in);

boolean done = false;

while (!done)

{

int input = in.next();

if(input.equalsIgnoreCase("q"))

done = false;

}

What will cause the loop to terminate?

a) When the user enters -1

b) The loop will never terminate

c) When the user enters q or Q

d) When the user enters done

Answer : Option B - The loop will never terminate

Question 3 : How many times will this for loop execute?

for (int i = 2; i < 10; i +=3)

{

...

}

a) 6

b) 3

c) 5

d) 4

Answer : Option B - 3 times

Question 4: A package is any program with two or more classes:

True or False

Answer : True

Package is a collection of related classes that we are using in our programming by reusability of the oops concepts.

Add a comment
Know the answer?
Add Answer to:
What will be the value of x after the following code is executed? int x =...
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
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