Home java Java. Why is it only a whole part?

Java. Why is it only a whole part?

Author

Date

Category

For example, when entering the number 13, it gives the answer 3.0


Answer 1, Authority 100%

Because B int and 4 too int
Row Double C = b / 4; works like this:

double c = (double) (b / 4);

first occurs integer division, and then bringing to double ;

To the division was not integer Write:

double c = b / 4.0;

In this case, b will be Double everything will be correct.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions