按照你的要求編寫的分段函數的Java程序如下
importjava.util.Scanner;publicclassSegment{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);doublex=sc.nextDouble();doubley;if(x<-5){y=3*x*x+2*x-1;}elseif(x>=-5&&x<=5){y=x*Math.sin(x)+Math.pow(2,x);}else{y=Math.sqrt(x-5)+Math.log10(x);}System.out.println("y="+y);}}運行結果輸入6輸出y=1.7781512503836436