Home >Java >javaTutorial >A classic Java programming question
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+"米。"); } }
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!