Question

Write the output of the following segment of code
0 0
Add a comment Improve this question Transcribed image text
Answer #1

int x = 7, y = 4, z;
       float z1,z2,z3;
      
       // x/y is 1.75 but integer by integer division gives an integer, thus x = 7/4 = 1
       // assigned to z1 and converted to float , thus z1 = 1.00
       z1 = x/y;

       // x/y is 1.75 but integer by integer division gives an integer, thus x = 7/4 = 1
       // which is then converted to float and assigned to z2
       // thus z2= 1.00
       z2 = (float)(x/y);

       // (float)x = 7.00, divided by y =4 , result is assigned to z3
       z3 = (float)x/y;

       // x/y is 1.75 but integer by integer division gives an integer, thus x = 7/4 = 1
       // assigned to z
       z = x/y;

       System.out.printf("z=%d z1=%5.2f z2=%5.2f z3=%5.2f \n",z,z1,z2,z3);

/*
output:
z=1 z1= 1.00 z2= 1.00 z3= 1.75

*/


Add a comment
Know the answer?
Add Answer to:
Write the output of the following segment of code and explain your results. int x=7, y=4,...
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
ADVERTISEMENT