Home > Java > javaTutorial > A classic Java programming question

A classic Java programming question

怪我咯
Release: 2017-06-26 11:53:28
Original
1153 people have browsed it

A ball falls freely from a height of 100 meters. Each time it hits the ground, it bounces back to half of its original height. It falls again... How many meters does it pass when it hits the ground for the 10th time? How high is the 10th rally?

public class Example10 {
    public static void main(String[] args) {
        height();
    }
    public static void height() {
        double sum = 0;
        double h = 100;
        for (int i = 0; i < 10; i++) {
            sum += h;
            h = h / 2;
        }
        System.out.println("共经过"+sum+"米。第10次反弹"+h+"米。");
    }
}
Copy after login


The above is the detailed content of A classic Java programming question. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template