public class text1 { public static void main(String[] args) { String strx = javax.swing.JOptionPane.showInputDialog("输入数值"); int x = Integer.parseInt(strx); if (x < 0) { x=0; } else if (x < 10) { x=x; } else if (x < 30) { x = x + 10; } else if (x > 40) { x = -x; } else { x = -x - 10; } System.out.println("Y=" + x); } }
使用选择结构实现如下数学分段函数的功能。要求:(1)设x为整数,其值由用户通过小窗口的形式进行输入;(2)根据所输入的x值,打印输出其分段函数中对应y的值。
最新推荐文章于 2023-04-03 16:36:18 发布