A-A+

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

2022-08-06 02:27:52 问答库 阅读 174 次

问题详情

编写程序,计算下列分段函数的值。
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);}}

考点:函数,程序