编写程序,计算下列分段函数的值。x? (x>=0)y=-x? (x编写程序,计算下列分段函数的值。x? (x>=0)y=-x? (x

题目
编写程序,计算下列分段函数的值。x? (x>=0)y=-x? (x<0)

编写程序,计算下列分段函数的值。

x? (x>=0)

y=

-x? (x<0)


相似考题
参考答案和解析
答案:import java.io.*;public class testa{ public static void main(String[] args) throws IOException{float? x,y;InputStreamReader reader=new InputStreamReader(System.in);BufferedReader input=new BufferedReader(reader);System.out.println("请输入x:");String temp=input.readLine();x = Float.parseFloat(temp);if(x>=0){y=x;}else{y=-x;}System.out.println("y="+y);}}