Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For questions asking \"What\'s wrong?\" Just write a part of a sentence or a few

ID: 3909741 • Letter: F

Question

For questions asking "What's wrong?" Just write a part of a sentence or a few words to describe the problem ( I've included the correct answers, but I need help understanding parts of them). In some cases the answer may be "Nothing" if the code segment is perfectly legal. For questions asking "What is the output?" just print out what you think will appear on the screen as the output of the print statements

a) What's wrong with code segment ?

int x=5;

String s="10";

x += s;

Answer for a:

x+ =s expands to x = x + s

x + s produces a string which cant be assigned into x (an int)

Could you please describe why this isnt possible?

............................................................................

b) What's wrong with code segment ?

int x=5;

String s="10";

s += x;

Answer for b:

s += x expands to s =s+x

s + x produces a string which can be assigned back into s

So there is nothing wrong with the code. But can you explain how the code can be assigned back into s?

............................................................................

c) What's the output of this code segment ?

int x=5,y=10;

System.out.println( "x + y = " + x + y );

Answer for c: x + y = 510

For this problem can you explain how they found the number 510?

............................................................................

d) What is the output of this code segment?

int i=50;

while ( i < 25 )

System.out.print( "* ");

System.out.println(" That's all folks!");

Answer for d: That's all folks!

For this problem can you explain what the notation means?

............................................................................

e) What is the output of this code segment?

boolean inputOk = true;

if (inputOk)

System.out.println("Thank you");

System.out.println("Your Input was OK");

if (!inputOk)

System.out.println("Sorry - try again you");

System.out.println("Your Input was bad");

For answer e: Thank you, Your input was ok, Your input was bad

Can you explain how they got the solutions in this order?

Thanks!

Explanation / Answer

If you have any doubts, please give me comment...

For a & b are correct, already gives the correct explanation

c)

In Java + used for concatenate of strings x = 5, y = 10 and both will concatenate then x+y is 510

if we use

System.out.println("x+y = "+(x+y)); then you will get sum of two numbers i.e., 15

d)

i=50

while(50<25) //it is false, so while condition not allowed for next statement.

so it will print one new line then print That's all folks!

indicates printing of new line

e)

inputOk = true

if(true) // condition is true, so allowed to inner then prints Thank you

then prints Your Input was OK

if(false) //!true is false, condition is false, it will not allowed to inner

after prints Your Input was bad

If any part that you still didn't understood, please give me comment...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote