package day04; public class Day04_Multi_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); } }
11-30
4699
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)