package Day04.Multi; public class IF { public static void main(String[] args) { java.util.Scanner input =new java.util.Scanner(System.in); System.out.println("请输入一个整数:"); int x = input.nextInt(); /* (1)x>=3; y=2x+1; (2)-1<=x<3; y=2x; (3)x<-1; y=2x-1; */ int y; //多分枝语句 实现上面的分段函数 if(x>=3){ y=2*x+1; } else if (-1<=x && x<3) { y=2*x; }else{ y=2*x-1; } System.out.println("y的值是:"+y); } }
10-06
5125
07-14
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交