题解 | #小球走过路程计算#
小球走过路程计算
http://www.nowcoder.com/practice/ddbb7021c0a7452f9044564234616913
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
float h=scanner.nextFloat();
int n =scanner.nextInt();
float sum =0;
for (int i = 0 ; i <n;i++){
sum=sum+h;
h=h/2;
sum=sum+h;
}sum=sum-h;
//write your code here......
System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
float h=scanner.nextFloat();
int n =scanner.nextInt();
float sum =0;
for (int i = 0 ; i <n;i++){
sum=sum+h;
h=h/2;
sum=sum+h;
}sum=sum-h;
//write your code here......
System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
}
}