实验2-2-4 计算分段函数[2]
package com.company; import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Scanner sc=new Scanner(System.in); double x=sc.nextDouble(); double result; DecimalFormat df=new DecimalFormat("0.00"); if(x>=0){ result=Math.pow(x,0.5); }else{ result=Math.pow(x+1,2)+2*x+1/x; } System.out.println("f("+df.format(x)+") = "+df.format(result)); } }
勿在浮沙筑高台