Java弹球题

package com.day2;
import java.util.*;
public class test10 {
    public static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入第几次?");
        int num = input.nextInt();
        double sum = 0, high = 100;
        for (int i = 1; i < num; i++) {
            if(i == 1)
                sum += high;
            else
                sum = sum + 2*high;
            if(i < 10)
                high /= 2;
        }
        System.out.println("第"+num+"次时经过"+sum+"米,第"+num+"次反弹"+high+"米!");
    }
}

你可能感兴趣的:(Java弹球题)