题解 | #小球走过路程计算#
小球走过路程计算
http://www.nowcoder.com/practice/ddbb7021c0a7452f9044564234616913
import java.util.Scanner; import java.lang.String;
public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); float h=scanner.nextFloat(); int n =scanner.nextInt();
//write your code here......
float sum = 0;
int i = 0;
//至少落地一次,所以采用do while循环
do{
if(i == 0){
sum = sum + h;
}else{
sum = sum + 2 * h;
}
h = h/2;
i++;
}while(i < n);
//输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
}
}