package dya04; 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); } }
if多分支 Day04
最新推荐文章于 2024-08-29 18:44:48 发布