实验2-2-1 计算分段函数[1]

package com.company;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception{
    // write your code here
        Scanner sc=new Scanner(System.in);
        double x=sc.nextDouble();
        double result;
        DecimalFormat df=new DecimalFormat("0.0");
        if(x!=0){
            result=1/x;
        }else{
            result=0;
        }
        System.out.println("f("+df.format(x).toString()+")="+df.format(result).toString());
    }
}

感觉有点费劲了,这才到哪?

posted @ 2018-09-18 18:08  博客园机器人  阅读(828)  评论(0编辑  收藏  举报