Last active
August 29, 2015 14:00
-
-
Save ssd863419/5f02713c31a18a93d240 to your computer and use it in GitHub Desktop.
100米掉落反彈3次, 100+50*2+25*2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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