参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double x = scanner.nextDouble(); double y = 0; if(x >= 0 && x < 5) y = -x + 2.5; else if(x >= 5 && x < 10) y = 2 - 1.5 * (x - 3) * (x - 3); else y = x / 2 - 1.5; System.out.printf("%.3f", y); } }
0.0分
5 人评分