首页 >计算机类 >JAVA认证 > >编写程序,计算下列分段函数的值。

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

时间:2019-11-01 06:40浏览次数:

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);}}

    阅读排行