Question

If you divide 1 by 2, you get 0.5. If you divide it again by 2,...

If you divide 1 by 2, you get 0.5. If you divide it again by 2, you get 0.25. Write a program that calculates and outputs the number of times you have to divide 1 by 2 to get a value less than one ten-thousandth (0.0001). Java program

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class NumDivisions {

    public static void main(String[] args) {
        int count = 0;
        double num = 1;
        while (num >= 0.0001) {
            ++count;
            num /= 10;
        }
        System.out.println("Number of divisions to get a value less than 0.0001 is " + count);
    }
}

Add a comment
Know the answer?
Add Answer to:
If you divide 1 by 2, you get 0.5. If you divide it again by 2,...
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