在#盖世猪猪#的解法上增加一个判断
求解立方根
https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); double input_old=in.nextDouble(); double input=input_old>0?input_old:-input_old; double top=0; double bottom=0; while(top*top*top<input){ top++; } bottom=top-1; double mid=bottom+(top-bottom)/2; double mul=mid*mid*mid; while(top-bottom>0.1){ if(mul>input){ top=mid; }else if(mul<input){ bottom=mid; }else{ break; } mid=bottom+(top-bottom)/2; mul=mid*mid*mid; } if(input_old<0){ mid=-mid; } System.out.println(String.format("%.1f",mid)); } }