Skip to content

Instantly share code, notes, and snippets.

@ssd863419
Last active August 29, 2015 14:00
Show Gist options
  • Save ssd863419/5f02713c31a18a93d240 to your computer and use it in GitHub Desktop.
Save ssd863419/5f02713c31a18a93d240 to your computer and use it in GitHub Desktop.
100米掉落反彈3次, 100+50*2+25*2
import java.util.Scanner;
public class Test {
public static float dropSum(int heigh , int times){
float result = 0;
float temp = 0;
for (int i = 1; i <=times ; i++) {
if (i == 1) {
temp = heigh;
result += heigh;
}else{
temp = temp/2;
result += temp*2;
}
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inPut ;
int inPut2;
do {
System.out.print("input heigh(0 to quit) :");
inPut = scanner.nextInt();
System.out.println();
if (inPut != 0) {
System.out.print("times : ");
inPut2 = scanner.nextInt();
System.out.println();
System.out.println("dropSum : " + dropSum(inPut , inPut2));
}
}while ( inPut !=0);
System.out.println("TKS");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment