package day02; 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); } }
多分支语句
最新推荐文章于 2024-06-17 14:36:58 发布