編程1:有一堆蘋果,N個熊分蘋果,第一個熊將這堆蘋果分N份後發現多一個,扔了一個並拿走了一份。第二個熊將剩下的蘋果也分N份後,發現多一個,扔了一個並拿走了一份,第三個,第四個直到第N個熊也都是這樣做的,求這堆蘋果至少有多少個?
求解答???做的沒A
編程題2: 4個同學站在不同的高度,分別拋出手中的小球,小球做自由落體運動,小球每次彈起的高度是原高度的一半。求直到球停在地面不動時,4個同學的小球所經過的路徑的總長度。輸入4個同學所站的高度,輸出總路徑和。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double totalLength = 0; int array[] = new int[4]; int i=0; while(i<4){ array[i++] = sc.nextInt(); } for(int j=0; j<4;j++) { totalLength += calculate(array[j]); } System.out.print(totalLength); } private static double calculate(double highLength) { int length = 0; while(highLength!=0){ length += highLength; highLength = highLength/2; } return length; } }