Title: A ball from the height of 100 meters of freedom falling, each landing back to the original height of half, and then down, to ask it to fall on the 10th time, the total number of meters? How high is the 10th time rebound?
ImportJava.util.Scanner; Public classTestone {/** * @paramargs*/ Private Doubletotalheight=100; Private DoubleCurheight=50; //whereabouts Public voidDropintTimes ) { if((times-1) ==0){ return ; } settotalheight (Gettotalheight ()+2*getcurheight ()); Setcurheight (Getcurheight ()/2); Drop ( times-1); } Private voidSetcurheight (Doublecurheight) {curheight=Curheight; } Public voidSettotalheight (Doubletotalheight) {totalheight=Totalheight; } Public Doublegetcurheight () { returnCurheight; } Public Doublegettotalheight () { returnTotalheight; } Public Static voidMain (string[] args) {System.out.println ("Please enter the number of times:"); Scanner SC=NewScanner (system.in); intI=Sc.nextint (); Testone Main=NewTestone (); Main.drop (i); System.out.println ("Total height is" +main.gettotalheight ()); System.out.println ("Last bounce height is" +main.getcurheight ()); }}
Java interview one question per day